索引

文档: https://developer.adobe.com/commerce/php/development/components/indexing/

索引流程

2024041615231789.png

索引器的状态

DATABASE STATUS
数据库状态
ADMIN STATUSDESCRIPTION
validReadyData is synchronized, no reindex required
数据已同步,不需要重新编制索引
invalidReindex Required
需要重新编制索引
The original data was changed, the index should be updated
原始数据已更改,应更新索引
workingProcessingIndexing is in progress
索引正在进行中

索引触发时机

索引优化

通过实验确定批处理的数量,通常批处理的数量越小,索引总时间越少。

通过环境变量配置批处理数量

<?php
return [
'indexer' => [
'batch_size' => [
'cataloginventory_stock' => [
'simple' => 200
],
'catalog_category_product' => 666,
'catalogsearch_fulltext' => [
'partial_reindex' => 100,
'mysql_get' => 500,
'elastic_save' => 500
],
'catalog_product_price' => [
'simple' => 200,
'default' => 500,
'configurable' => 666
],
'catalogpermissions_category' => 999,
'inventory' => [
'simple' => 210,
'default' => 510,
'configurable' => 616
]
]
]
];

通过 di.xml 依赖注入设置

....
<type name="Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\BatchSizeCalculator">
<arguments>
<argument name="batchRowsCount" xsi:type="array">
<item name="configurable" xsi:type="number">5000</item>
</argument>
</arguments>
</type>
...
<type name="Magento\CatalogInventory\Model\Indexer\Stock\Action\Full">
<arguments>
<argument name="batchRowsCount" xsi:type="array">
<item name="configurable" xsi:type="number">200</item>
</argument>
</arguments>
</type>

索引期间支持表切换

todo

EAV 索引器优化

todo