From c80710a023a1ff6ca3c13f2cc3ba2a867e482638 Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Sat, 11 Nov 2017 13:03:32 +0000 Subject: [PATCH] Add mview getListSize command --- .../Command/IndexerStatusMviewCommand.php | 2 +- .../Command/IndexerStatusMviewCommandTest.php | 9 ++--- .../Framework/Mview/View/Changelog.php | 36 ++++++++++++++++--- .../Mview/View/ChangelogInterface.php | 9 +++++ 4 files changed, 45 insertions(+), 11 deletions(-) diff --git a/app/code/Magento/Indexer/Console/Command/IndexerStatusMviewCommand.php b/app/code/Magento/Indexer/Console/Command/IndexerStatusMviewCommand.php index 0efeef4a71be5..37caabc613e66 100644 --- a/app/code/Magento/Indexer/Console/Command/IndexerStatusMviewCommand.php +++ b/app/code/Magento/Indexer/Console/Command/IndexerStatusMviewCommand.php @@ -61,7 +61,7 @@ protected function execute(InputInterface $input, OutputInterface $output) continue; } - $pendingCount = count($changelog->getList($state->getVersionId(), $currentVersionId)); + $pendingCount = $changelog->getListSize($state->getVersionId(), $currentVersionId); $pendingString = "$pendingCount"; if ($pendingCount <= 0) { diff --git a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusMviewCommandTest.php b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusMviewCommandTest.php index 292adb55c5533..4ae3ca83870e7 100644 --- a/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusMviewCommandTest.php +++ b/app/code/Magento/Indexer/Test/Unit/Console/Command/IndexerStatusMviewCommandTest.php @@ -176,14 +176,11 @@ protected function generateMviewStub(array $viewData, array $changelogData, arra ->disableOriginalConstructor() ->getMock(); - $list = []; - if ($changelogData['version_id'] !== $stateData['version_id']) { - $list = range($stateData['version_id']+1, $changelogData['version_id']); - } + $listSize = $changelogData['version_id'] - $stateData['version_id']; $changelog->expects($this->any()) - ->method('getList') - ->willReturn($list); + ->method('getListSize') + ->willReturn($listSize); $changelog->expects($this->any()) ->method('getVersion') diff --git a/lib/internal/Magento/Framework/Mview/View/Changelog.php b/lib/internal/Magento/Framework/Mview/View/Changelog.php index 91caf66228360..4f648d6b7d6ae 100644 --- a/lib/internal/Magento/Framework/Mview/View/Changelog.php +++ b/lib/internal/Magento/Framework/Mview/View/Changelog.php @@ -127,14 +127,12 @@ public function clear($versionId) } /** - * Retrieve entity ids by range [$fromVersionId..$toVersionId] - * * @param int $fromVersionId * @param int $toVersionId - * @return int[] + * @return \Magento\Framework\DB\Select * @throws ChangelogTableNotExistsException */ - public function getList($fromVersionId, $toVersionId) + protected function getListSelect($fromVersionId, $toVersionId) { $changelogTableName = $this->resource->getTableName($this->getName()); if (!$this->connection->isTableExists($changelogTableName)) { @@ -154,9 +152,39 @@ public function getList($fromVersionId, $toVersionId) (int)$toVersionId ); + return $select; + } + + /** + * Retrieve entity ids by range [$fromVersionId..$toVersionId] + * + * @param int $fromVersionId + * @param int $toVersionId + * @return int[] + * @throws ChangelogTableNotExistsException + */ + public function getList($fromVersionId, $toVersionId) + { + $select = $this->getListSelect($fromVersionId, $toVersionId); return $this->connection->fetchCol($select); } + /** + * Retrieve the count of entity ids in the range [$fromVersionId..$toVersionId] + * + * @param int $fromVersionId + * @param int $toVersionId + * @return int[] + * @throws ChangelogTableNotExistsException + */ + public function getListSize($fromVersionId, $toVersionId) + { + $countSelect = $this->getListSelect($fromVersionId, $toVersionId); + $countSelect->reset(\Magento\Framework\DB\Select::COLUMNS); + $countSelect->columns(new \Zend_Db_Expr(("COUNT(DISTINCT " . $this->getColumnName() . ")"))); + return $this->connection->fetchOne($countSelect); + } + /** * Get maximum version_id from changelog * @return int diff --git a/lib/internal/Magento/Framework/Mview/View/ChangelogInterface.php b/lib/internal/Magento/Framework/Mview/View/ChangelogInterface.php index b00c1ca3a2e33..da115ecdb83ee 100644 --- a/lib/internal/Magento/Framework/Mview/View/ChangelogInterface.php +++ b/lib/internal/Magento/Framework/Mview/View/ChangelogInterface.php @@ -42,6 +42,15 @@ public function clear($versionId); */ public function getList($fromVersionId, $toVersionId); + /** + * Retrieve the count of entity ids in the range [$fromVersionId..$toVersionId] + * + * @param $fromVersionId + * @param $toVersionId + * @return mixed + */ + public function getListSize($fromVersionId, $toVersionId); + /** * Get maximum version_id from changelog *