Merge pull request #4234 from naderman/rule-hash-int-size

Reduce rule hash size
main
Jordi Boggiano 9 years ago
commit acc11f63c5

@ -43,8 +43,6 @@ class Rule
protected $job; protected $job;
protected $ruleHash;
public function __construct(array $literals, $reason, $reasonData, $job = null) public function __construct(array $literals, $reason, $reasonData, $job = null)
{ {
// sort all packages ascending by id // sort all packages ascending by id
@ -55,17 +53,15 @@ class Rule
$this->reasonData = $reasonData; $this->reasonData = $reasonData;
$this->disabled = false; $this->disabled = false;
$this->job = $job; $this->job = $job;
$this->type = -1; $this->type = -1;
$this->ruleHash = substr(md5(implode(',', $this->literals)), 0, 5);
} }
public function getHash() public function getHash()
{ {
return $this->ruleHash; $data = unpack('ihash', md5(implode(',', $this->literals), true));
return $data['hash'];
} }
public function setId($id) public function setId($id)
@ -114,10 +110,6 @@ class Rule
*/ */
public function equals(Rule $rule) public function equals(Rule $rule)
{ {
if ($this->ruleHash !== $rule->ruleHash) {
return false;
}
if (count($this->literals) != count($rule->literals)) { if (count($this->literals) != count($rule->literals)) {
return false; return false;
} }

@ -30,7 +30,8 @@ class RuleTest extends TestCase
{ {
$rule = new Rule(array(123), 'job1', null); $rule = new Rule(array(123), 'job1', null);
$this->assertEquals(substr(md5('123'), 0, 5), $rule->getHash()); $hash = unpack('ihash', md5('123', true));
$this->assertEquals($hash['hash'], $rule->getHash());
} }
public function testSetAndGetId() public function testSetAndGetId()

Loading…
Cancel
Save