Skip to content

Commit 09eb0fc

Browse files
committed
MC-37630: Updating Design Configuration runs full reindex which generates DDL statement DROP Table
1 parent 14e8412 commit 09eb0fc

File tree

4 files changed

+24
-35
lines changed

4 files changed

+24
-35
lines changed

app/code/Magento/Theme/Model/Indexer/Design/Config.php

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
namespace Magento\Theme\Model\Indexer\Design;
77

8-
use Magento\Framework\App\ObjectManager;
98
use Magento\Framework\Indexer\ActionInterface;
109
use Magento\Framework\Indexer\FieldsetPool;
1110
use Magento\Framework\Indexer\HandlerPool;
@@ -94,30 +93,13 @@ protected function execute(array $ids = [])
9493
/** @var \Magento\Theme\Model\ResourceModel\Design\Config\Scope\Collection $collection */
9594
$collection = $this->collectionFactory->create();
9695
$this->prepareFields();
97-
98-
$tmp = $this->isFlatTableExists();
99-
100-
if (!$this->isFlatTableExists()) {
101-
// instead of clean index check if table exists and create it if not
96+
if (!count($ids)) {
10297
$this->getSaveHandler()->cleanIndex([]);
10398
}
10499
$this->getSaveHandler()->deleteIndex([], new \ArrayObject($ids));
105100
$this->getSaveHandler()->saveIndex([], $collection);
106101
}
107102

108-
private function isFlatTableExists()
109-
{
110-
/** @var \Magento\Framework\App\ResourceConnection $resource */
111-
$resource = ObjectManager::getInstance()->get(\Magento\Framework\App\ResourceConnection::class);
112-
113-
/** @var \Magento\Framework\DB\Adapter\AdapterInterface $connection */
114-
$connection = ObjectManager::getInstance()->get(\Magento\Framework\App\ResourceConnection::class)->getConnection();
115-
116-
$tableName = $resource->getTableName('design_config_grid_flat');
117-
118-
return $connection->isTableExists($tableName);
119-
}
120-
121103
/**
122104
* Execute full indexation
123105
*

app/code/Magento/Theme/Model/Indexer/Design/IndexerHandler.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,29 @@ public function __construct(
4444
}
4545

4646
/**
47-
* Clean index table by truncation
47+
* @return bool
48+
*/
49+
private function isFlatTableExists()
50+
{
51+
$adapter = $this->resource->getConnection('write');
52+
$tableName = $this->flatScopeResolver->resolve($this->getIndexName(), []);
53+
54+
return $adapter->isTableExists($tableName);
55+
}
56+
57+
/**
58+
* Clean index table by deleting all records
4859
*
4960
* @inheritdoc
5061
*/
5162
public function cleanIndex($dimensions)
5263
{
53-
$adapter = $this->resource->getConnection('write');
54-
$tableName = $this->flatScopeResolver->resolve($this->getIndexName(), $dimensions);
55-
if ($adapter->isTableExists($tableName)) {
56-
$adapter->truncateTable($tableName);
64+
if ($this->isFlatTableExists()) {
65+
$adapter = $this->resource->getConnection('write');
66+
$tableName = $this->flatScopeResolver->resolve($this->getIndexName(), $dimensions);
67+
$adapter->delete($tableName);
68+
} else {
69+
$this->indexStructure->create($this->getIndexName(), $this->fields, $dimensions);
5770
}
5871
}
5972
}

app/code/Magento/Theme/etc/indexer.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<field name="store_group_id" xsi:type="filterable" dataType="int"/>
1818
<field name="store_id" xsi:type="filterable" dataType="int"/>
1919
</fieldset>
20-
<saveHandler class="Magento\Framework\Indexer\SaveHandler\Grid"/>
20+
<saveHandler class="Magento\Theme\Model\Indexer\Design\IndexerHandler"/>
2121
<structure class="Magento\Framework\Indexer\GridStructure"/>
2222
</indexer>
2323
</config>

lib/internal/Magento/Framework/Indexer/SaveHandler/Grid.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,10 @@ protected function prepareFilterableFields(array $documents)
6969
*/
7070
public function deleteIndex($dimensions, \Traversable $ids)
7171
{
72-
if (!empty(iterator_to_array($ids))) {
73-
foreach ($this->batch->getItems($ids, $this->batchSize) as $batchIds) {
74-
$this->connection->delete(
75-
$this->getTableName('filterable', $dimensions),
76-
['entity_id IN(?)' => $batchIds]
77-
);
78-
}
79-
} else {
80-
$this->connection->truncateTable(
81-
$this->getTableName('filterable', $dimensions)
72+
foreach ($this->batch->getItems($ids, $this->batchSize) as $batchIds) {
73+
$this->connection->delete(
74+
$this->getTableName('filterable', $dimensions),
75+
['entity_id IN(?)' => $batchIds]
8276
);
8377
}
8478
}

0 commit comments

Comments
 (0)