Skip to content
Snippets Groups Projects
Commit c80710a0 authored by Luke Rodgers's avatar Luke Rodgers
Browse files

Add mview getListSize command

parent f4857ec2
Branches
No related merge requests found
......@@ -61,7 +61,7 @@ class IndexerStatusMviewCommand extends Command
continue;
}
$pendingCount = count($changelog->getList($state->getVersionId(), $currentVersionId));
$pendingCount = $changelog->getListSize($state->getVersionId(), $currentVersionId);
$pendingString = "<error>$pendingCount</error>";
if ($pendingCount <= 0) {
......
......@@ -176,14 +176,11 @@ class IndexerStatusMviewCommandTest extends \PHPUnit\Framework\TestCase
->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')
......
......@@ -127,14 +127,12 @@ class Changelog implements ChangelogInterface
}
/**
* 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 @@ class Changelog implements ChangelogInterface
(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
......
......@@ -42,6 +42,15 @@ interface ChangelogInterface
*/
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
*
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment