Skip to content

Commit

Permalink
Add mview getListSize command
Browse files Browse the repository at this point in the history
  • Loading branch information
convenient committed Nov 11, 2017
1 parent f4857ec commit c80710a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<error>$pendingCount</error>";
if ($pendingCount <= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
36 changes: 32 additions & 4 deletions lib/internal/Magento/Framework/Mview/View/Changelog.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit c80710a

Please sign in to comment.