Skip to content

Commit

Permalink
attempt optimisation
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Green committed Jan 15, 2015
1 parent 6d1289c commit 5818d0c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions src/DbSync/Comparison/Hash.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class Hash extends HashAbstract {

protected $start;

protected $lastComparisonEmpty = false;

private static $intTypes = array(
'tinyint',
'smallint',
Expand Down Expand Up @@ -149,7 +151,12 @@ private function buildComparisonHash()

public function nextValidIndex($block)
{
return $this->limitKey ? ($this->getAggregateCount('MIN', $block) ?: $block) : $block;
if($this->limitKey && $this->lastComparisonEmpty)
{
return $this->getAggregateCount('MIN', $block) ?: $block;
}

return $block;
}

private function compareLimit($offset, $blockSize)
Expand Down Expand Up @@ -189,7 +196,13 @@ public function compare($offset, $blockSize)
{
$query = $this->limitKey ? $this->compareIndex($offset, $blockSize) : $this->compareLimit($offset, $blockSize);

if($this->source->fetchOne(sprintf($query,$this->sourcetable)) === $this->destination->fetchOne(sprintf($query,$this->desttable)))
$sourceHash = $this->source->fetchOne(sprintf($query,$this->sourcetable));

$destHash = $this->destination->fetchOne(sprintf($query,$this->desttable));

$this->lastComparisonEmpty = $sourceHash ? false : true;

if($sourceHash === $destHash)
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
'host' => 'localhost',
'driver' => 'mysql',
'username' => 'root',
'password' => '',
'password' => 'password',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
Expand Down

0 comments on commit 5818d0c

Please sign in to comment.