Skip to content

Commit a738ddf

Browse files
committed
MAGETWO-63945: Add extension point to sales grid indexer
- Getting rid of redundant query in UpdatedIdList provider
1 parent 89f33cd commit a738ddf

File tree

2 files changed

+19
-26
lines changed

2 files changed

+19
-26
lines changed

app/code/Magento/Sales/Model/ResourceModel/Grid.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Grid extends AbstractGrid
4343
/**
4444
* @var NotSyncedDataProviderInterface
4545
*/
46-
private $idListProvider;
46+
private $notSyncedDataProvider;
4747

4848
/**
4949
* @param Context $context
@@ -53,7 +53,7 @@ class Grid extends AbstractGrid
5353
* @param array $joins
5454
* @param array $columns
5555
* @param string $connectionName
56-
* @param NotSyncedDataProviderInterface $idListProvider
56+
* @param NotSyncedDataProviderInterface $notSyncedDataProvider
5757
*/
5858
public function __construct(
5959
Context $context,
@@ -63,15 +63,15 @@ public function __construct(
6363
array $joins = [],
6464
array $columns = [],
6565
$connectionName = null,
66-
NotSyncedDataProviderInterface $idListProvider = null
66+
NotSyncedDataProviderInterface $notSyncedDataProvider = null
6767
) {
6868
$this->mainTableName = $mainTableName;
6969
$this->gridTableName = $gridTableName;
7070
$this->orderIdField = $orderIdField;
7171
$this->joins = $joins;
7272
$this->columns = $columns;
73-
$this->idListProvider =
74-
$idListProvider ?: ObjectManager::getInstance()->get(NotSyncedDataProviderInterface::class);
73+
$this->notSyncedDataProvider =
74+
$notSyncedDataProvider ?: ObjectManager::getInstance()->get(NotSyncedDataProviderInterface::class);
7575
parent::__construct($context, $connectionName);
7676
}
7777

@@ -111,7 +111,7 @@ public function refreshBySchedule()
111111
$select = $this->getGridOriginSelect()
112112
->where(
113113
$this->mainTableName . '.entity_id IN (?)',
114-
$this->idListProvider->get($this->mainTableName, $this->gridTableName)
114+
$this->notSyncedDataProvider->getIds($this->mainTableName, $this->gridTableName)
115115
);
116116

117117
return $this->getConnection()->query(

app/code/Magento/Sales/Model/ResourceModel/Provider/UpdatedIdListProvider.php

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,31 +38,24 @@ public function __construct(
3838
*/
3939
public function getIds($mainTableName, $gridTableName)
4040
{
41-
$lastUpdatedAt = $this->getLastUpdatedAtValue($gridTableName);
4241
$select = $this->getConnection()->select()
43-
->from($this->getConnection()->getTableName($mainTableName), ['entity_id'])
44-
->where('updated_at >= ?', $lastUpdatedAt);
42+
->from($this->getConnection()->getTableName($mainTableName), [$mainTableName.'.entity_id'])
43+
->joinLeft(
44+
[$gridTableName => $this->getConnection()->getTableName($gridTableName)],
45+
sprintf(
46+
'%s.%s = %s.%s',
47+
$mainTableName,
48+
'entity_id',
49+
$gridTableName,
50+
'entity_id'
51+
),
52+
[]
53+
)
54+
->where($gridTableName.'.entity_id IS NULL');
4555

4656
return $this->getConnection()->fetchAll($select, [], \Zend_Db::FETCH_COLUMN);
4757
}
4858

49-
/**
50-
* Returns update time of the last row in the grid.
51-
*
52-
* @param string $gridTableName
53-
* @return string
54-
*/
55-
private function getLastUpdatedAtValue($gridTableName)
56-
{
57-
$select = $this->getConnection()->select()
58-
->from($this->getConnection()->getTableName($gridTableName), ['updated_at'])
59-
->order('updated_at DESC')
60-
->limit(1);
61-
$row = $this->getConnection()->fetchRow($select);
62-
63-
return isset($row['updated_at']) ? $row['updated_at'] : '0000-00-00 00:00:00';
64-
}
65-
6659
/**
6760
* Returns connection.
6861
*

0 commit comments

Comments
 (0)