定制 aligent/magento2-indexer-fix 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

aligent/magento2-indexer-fix

Composer 安装命令:

composer require aligent/magento2-indexer-fix

包简介

Fix to core Magento scheduled indexing to avoid inconsistent index data

README 文档

README

This module is designed to fix a common issue around the scheduled "mview" indexing within Magento 2.

Background

When indexers are set to update by schedule, the scenario is as follows:

  • Each indexer has a corresponding changelog database table.
  • Each indexer subscribes to a number of database tables - when a change is made in a subscribed table, a record is added to the changelog table for the indexer.

Additionally, some indexers use the data created by another indexer. For example, the catalogsearch_fulltext indexer may use indexed category and price data.

Indexed data is updated via the indexer_update_all_views cron job. This job loops through all scheduled indexers and updates its data based on the latest changelog record for each one.

Issue

When indexer_update_all_views runs, it will get the changelog information for a single indexer, process it, and then move on to the next one. Consider the following scenario:

  1. The mview_state table has version_id of 100 for both catalog_product_price and catalogsearch_fulltext records.
  2. Both catalog_product_price_cl and catalogsearch_fulltext_cl changelog tables are also at version 100.
  3. The prices of 10 products are updated
    1. This adds 10 records to catalog_product_price_cl and catalogsearch_fulltext_cl
    2. Latest version in the changelog tables is now 110
  4. indexer_update_all_views begins, and starts to process the catalog_product_price indexer.
    1. It determines that it needs to process changelog records 101-110
  5. Before the price indexer has finished processing, 10 more product prices are updated.
    1. 10 more recrds are added to catalog_product_price_cl and catalogsearch_fulltext_cl
    2. Latest version in the changelog tables is now 120
  6. indexer_update_all_views finishes processing the price indexer, and moves on to catalogsearch_fulltext
    1. It determines that it needs to process changelog records 101-120
  7. indexer_update_all_views completes
  8. The next run of indexer_update_all_views processes records 111-120 for the price indexer.

After this, everything seems to be up to date - this is not the case. Since the catalogsearch_fulltext indexer uses indexed price data, when it processed records 101-120, it did not have up-to-date data for 111-120, as these had not yet been processed by the price indexer.

The products corresponding to these last 10 changelog records will not be updated by the catalogsearch_fulltext indexer again until either:

  • The index is invalidated and a full re-index is performed.
  • The product gets updated again in some way.

Fix

In order to avoid timing issues relating to updates happening at the same time as index processing, this module does the following:

  • Before indexer_update_all_views begins processing, a snapshot of all changelog tables is taken, recording the (at the time) latest version number.
  • An around plugin is added to the ChangelogInterface->getVersion function, so that the snapshot version is returned
    • If a snapshot does not exist, it is looked up from the database as per normal functionality

By doing this, any new changelog records that are created while the job is running will be ignored, and instead processed by the next run.

Installation

To install this module, the following commands can be run:

composer require aligent/magento2-indexer-fix
bin/magento module:enable Aligent_IndexerFix
bin/magento setup:upgrade

aligent/magento2-indexer-fix 适用场景与选型建议

aligent/magento2-indexer-fix 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 24.05k 次下载、GitHub Stars 达 10, 最近一次更新时间为 2023 年 01 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 aligent/magento2-indexer-fix 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 aligent/magento2-indexer-fix 我们能提供哪些服务?
定制开发 / 二次开发

基于 aligent/magento2-indexer-fix 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 24.05k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 10
  • 点击次数: 24
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 10
  • Watchers: 8
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-only
  • 更新时间: 2023-01-05