From 5818d0c140cddb0a0292b0644a461f3a970f04e2 Mon Sep 17 00:00:00 2001 From: Joe Green Date: Thu, 15 Jan 2015 17:02:29 +0000 Subject: [PATCH] attempt optimisation --- src/DbSync/Comparison/Hash.php | 17 +++++++++++++++-- tests/integration/config.php | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/DbSync/Comparison/Hash.php b/src/DbSync/Comparison/Hash.php index bcf699c..d0948f0 100644 --- a/src/DbSync/Comparison/Hash.php +++ b/src/DbSync/Comparison/Hash.php @@ -26,6 +26,8 @@ class Hash extends HashAbstract { protected $start; + protected $lastComparisonEmpty = false; + private static $intTypes = array( 'tinyint', 'smallint', @@ -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) @@ -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; } diff --git a/tests/integration/config.php b/tests/integration/config.php index 146b94b..4703717 100644 --- a/tests/integration/config.php +++ b/tests/integration/config.php @@ -4,7 +4,7 @@ 'host' => 'localhost', 'driver' => 'mysql', 'username' => 'root', - 'password' => '', + 'password' => 'password', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '',