ในเอกสารอย่างเป็นทางการ:
https://devdocs.magento.com/guides/v2.3/extension-dev-guide/indexing.html
มีการขโมย:
`Allows tracking database changes for a certain entity (product, category and so on) and running change handler.
Emulates the materialized view technology for MySQL using triggers and separate materialization process (provides executing PHP code instead of SQL queries, which allows materializing multiple queries).`
MView ย่อมาจาก Materialized View ซึ่งเป็นภาพรวมของฐานข้อมูล ณ เวลาหนึ่ง ๆ
https://en.wikipedia.org/wiki/Materialized_view
ทำไมเราต้องทำสำเนาตาราง ดัชนีมีค่าใช้จ่ายสูงโดยเฉพาะเมื่อมีปริมาณการใช้งานในหน้าหมวดหมู่ลูกค้าสั่งซื้อสินค้าและผู้ดูแลระบบบันทึกสินค้า ในผลิตภัณฑ์บันทึกแคชได้รับการตรวจสอบความถูกต้อง (นอกหัวข้อ) ในกรณีของตัวทำดัชนีหุ้นก่อนที่จะสิ้นสุดการดำเนินการมันจะส่งรหัสเอนทิตีที่ได้รับผลกระทบเป็นแท็กแคชที่จะทำความสะอาด (ประเภทแคชแบบเต็มหน้า) ในรหัสวีโอไอพีประเภท 2.0 ของผลิตภัณฑ์ที่ซื้อจะถูกส่งไป ใน Magento 2.1 รหัสผลิตภัณฑ์จะถูกส่งไป
มีตาราง MySQL 2 ตัวที่เก็บรหัสและสถานะของตัวทำดัชนี:
indexer_state
mview_state
mview_stateทำงานร่วมกับUpdate by Scheduleในผู้ดูแลระบบ> ระบบ> การจัดการดัชนี
Update by Schedule ทำให้ตัวสร้างดัชนีทำงานใน cron
มี 3 รายการในMagento_Indexer/etc/contab.xml:
<group id="index">
<job name="indexer_reindex_all_invalid" instance="Magento\Indexer\Cron\ReindexAllInvalid" method="execute">
<schedule>* * * * *</schedule>
</job>
<job name="indexer_update_all_views" instance="Magento\Indexer\Cron\UpdateMview" method="execute">
<schedule>* * * * *</schedule>
</job>
<job name="indexer_clean_all_changelogs" instance="Magento\Indexer\Cron\ClearChangelog" method="execute">
<schedule>0 * * * *</schedule>
</job>
</group>
indexer_reindex_all_invalidindexer_stateทำงานบน ยังคงมีความจำเป็นต้องเรียกใช้ตัวทำดัชนี 'ปกติ' ใน cron
indexer_update_all_views ทำงานอยู่ mview_state
indexer_clean_all_changelogs - ล้างการเปลี่ยนแปลงที่ใช้โดย mview_state
โปรดทราบว่ากลุ่มงาน cron ดัชนีทำงานในกระบวนการ PHP แยกประกาศ:etc/contab_groups.xml
<use_separate_process>1</use_separate_process>
ตารางการเปลี่ยนแปลงคือ:
[indexer name]_cl( _clต่อท้ายด้วย) cataloginventory_stock_clเช่น หากคุณมีตัวทำดัชนีตั้งค่าUpdate by Scheduleและบันทึกผลิตภัณฑ์ในผู้ดูแลระบบคุณจะเห็นentity_idผลิตภัณฑ์นั้นในตารางนี้ มันเป็นวงกลมใหญ่ฉันกำลังสั่งซื้อหรือสร้างการจัดส่งจะเพิ่มที่นี่ด้วย
มีคนให้ตัวอย่างใน devdoc อย่างเป็นทางการเกี่ยวกับวิธีการสร้างมุมมองที่เป็นรูปธรรมใหม่และวิธีการอินเทอร์เฟซที่ต้องการคืออะไร
<?php
<VendorName>\Merchandizing\Model\Indexer;
class Popular implements \Magento\Framework\Indexer\ActionInterface, \Magento\Framework\Mview\ActionInterface
{
public function executeFull(); //Should take into account all placed orders in the system
public function executeList($ids); //Works with a set of placed orders (mass actions and so on)
public function executeRow($id); //Works in runtime for a single order using plugins
public function execute($ids); //Used by mview, allows you to process multiple placed orders in the "Update on schedule" mode
}
สิ่งนี้จะสมเหตุสมผล:
//public function execute($ids); Used by mview, allows you to process multiple **entities** in the "Update on schedule" mode
}
โดยที่$idsพารามิเตอร์มีเอนทิตี id จาก*_clตาราง
การเชื่อมโยงระหว่างการตรวจสอบแคชและดัชนี ขณะนี้หน้าหมวดหมู่ถูกแคชแบบเต็มหน้า (แคชแบบเต็มหน้าในตัวหรือผ่านการเคลือบเงา)
มี\Magento\Indexer\Model\Processor\InvalidateCache::afterUpdateMview:
/**
* Update indexer views
*
* @param \Magento\Indexer\Model\Processor $subject
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterUpdateMview(\Magento\Indexer\Model\Processor $subject)
{
if ($this->moduleManager->isEnabled('Magento_PageCache')) {
$this->eventManager->dispatch('clean_cache_after_reindex', ['object' => $this->context]);
}
}
กลับไปที่Magento\Indexer\Cron\UpdateMview::execute():
/**
* Regenerate indexes for all invalid indexers
*
* @return void
*/
public function execute()
{
$this->processor->updateMview();
}
Magento\Indexer\Model\Processor::updateMview():
/**
* Update indexer views
*
* @return void
*/
public function updateMview()
{
$this->mviewProcessor->update('indexer');
}
ในapp/etc/di.xmlนั้นคือ:
<preference for="Magento\Framework\Mview\ProcessorInterface" type="Magento\Framework\Mview\Processor" />
/**
* Materialize all views by group (all views if empty)
*
* @param string $group
* @return void
*/
public function update($group = '')
{
foreach ($this->getViewsByGroup($group) as $view) {
$view->update();
}
}
Magento\Framework\Mview\ViewInterface
/**
* Materialize view by IDs in changelog
*
* @return void
* @throws \Exception
*/
public function update();
app/etc/di.xml
<preference for="Magento\Framework\Mview\ViewInterface" type="Magento\Framework\Mview\View" />
ในMagento\Framework\Mview\View::update()นั้นคือ:
$action = $this->actionFactory->get($this->getActionClass());
$this->getState()->setStatus(View\StateInterface::STATUS_WORKING)->save();
..
$action->execute($ids);
..
หากคุณค้นหาในvendor/ไดเรกทอรีMagento\Framework\Mview\ActionInterfaceคุณจะพบตัวอย่างนี้:
ใน\Magento\CatalogInventory\Model\Indexer:
class Stock implements \Magento\Framework\Indexer\ActionInterface, \Magento\Framework\Mview\ActionInterface
ในชั้นเรียนนี้มี:
/**
* Execute materialization on ids entities
*
* @param int[] $ids
*
* @return void
*/
public function execute($ids)
{
$this->_productStockIndexerRows->execute($ids);
}
และดูเหมือนว่าจะกลับไปที่ 'ปกติ' คลาสของ indexers 'method' ซึ่ง MView ใช้
เกี่ยวกับการล้างแคชหลังจาก Stock Indexer เมื่อมีการสั่งซื้อสินค้าเมื่อชำระเงินปริมาณจะถูกหักออกโดยใช้ผู้สังเกตการณ์นี้:\Magento\CatalogInventory\Observer\SubtractQuoteInventoryObserver
$itemsForReindex = $this->stockManagement->registerProductsSale(
$items,
$quote->getStore()->getWebsiteId()
);
นอกจากนี้ผู้สังเกตการณ์อีกคนหนึ่งเรียกใช้ตัวสร้างดัชนี (แต่ไม่ใช่โดยตรงบน Mview / ดัชนีตามตารางเวลา):
\Magento\CatalogInventory\Observer\ReindexQuoteInventoryObserver
if ($productIds) {
$this->stockIndexerProcessor->reindexList($productIds);
}
ในกรณี Mview เมื่อมีการลบจำนวนใหม่SubtractQuoteInventoryObserverทริกเกอร์ MySQL (สร้างขึ้นสำหรับ Mview) จะแทรกแถวในcataloginventory_stock_clทำเครื่องหมายว่าต้องการทำดัชนี (สต็อกและข้อความเต็ม) สำหรับรหัสผลิตภัณฑ์ที่ซื้อ มีทริกเกอร์ MySQL มากมายที่สร้างขึ้นสำหรับ Mview SHOW TRIGGERS;เห็นพวกเขาทั้งหมดที่มี
เมื่อสินค้าหมดหลังจากชำระเงินคุณจะเห็น 2 แถวแทรกอยู่ในตารางนั้น (วีโอไอพีจะประหยัด 2 เท่าของรายการสินค้าใน 2 ผู้สังเกตการณ์เหล่านี้)
เมื่อ cron รันตัวสร้างดัชนีหุ้นในโหมด Mview รหัสผลิตภัณฑ์ที่ได้รับผลกระทบ (ใน M2.1) หรือรหัสหมวดหมู่ (ใน M2.0) จะถูกส่งไปยังแคชสะอาดเป็นแท็กแคช โดยแคชฉันหมายถึงประเภทแคชแบบเต็มหน้า ตัวอย่าง: catalog_product_99หรือรูปแบบแคชแท็กอื่น ๆ ขึ้นอยู่กับเวอร์ชั่นของวีโอไอพี เช่นเดียวกันเมื่อไม่ได้เปิดใช้งาน Mview
\Magento\CatalogInventory\Model\Indexer\Stock\AbstractAction::_reindexRows
...
$this->eventManager->dispatch('clean_cache_by_tags', ['object' => $this->cacheContext]);
และ Magento_PageCache มีผู้สังเกตการณ์\Magento\PageCache\Observer\FlushCacheByTagsที่จะล้างแคชแบบเต็มหน้าด้วยแท็ก มันใช้สำหรับแคชแบบเต็มหน้าของ buil-in \Magento\CacheInvalidate\Observer\InvalidateVarnishObserverวานิชรหัสที่เกี่ยวข้องอยู่ใน
มีส่วนขยายฟรีที่จะปฏิเสธแคชที่ยังคงมีอยู่ในสต็อกผลิตภัณฑ์หลังจากชำระเงินของลูกค้า:
https://github.com/daniel-ifrim/innovo-cache-improve
การทำความสะอาดแคชเฉพาะสินค้าที่หมดหลังจากการชำระเงินถูกนำมาใช้ใน Magento 2.2.x ที่เป็นค่าเริ่มต้น \Magento\CatalogInventory\Model\Indexer\Stock\CacheCleanerดู
ฉันคิดว่าการดำเนินการ cron สำหรับตัวสร้างดัชนีAdmin > Stores > Configuration > Advanced > System > Cron configuration options for group: indexควรตั้งค่ามากกว่า 1 นาที
Mviewหมายถึงมุมมองที่ปรากฏขึ้นซึ่งเป็นสิ่งที่ตารางดัชนี