magento2-connector-community
magento2-connector-community copied to clipboard
Magento 2: Category Products Indexer Unnecessarily Triggered on Akeneo Sync Without Changes
The primary issue arises when initiating a category synchronization in Magento 2, even without making any modifications, which unexpectedly triggers the Category Products indexer to register changes. This occurs when the category sync job is executed, leading to the catalog_category_product_cl
changelog being populated twice. This duplication is caused by a trigger, despite no alterations being made in Akeneo. A closer examination reveals that only categories with subcategories are marked as altered in the changelog.
This issue is particularly problematic for our client, who manages extensive categories, resulting in prolonged indexing times. Additionally, other indexes dependent on the Category Products index are forced to wait, exacerbating the delay.
The problematic trigger is identified as follows:
BEGIN
IF (
NOT(NEW.`entity_id` <=> OLD.`entity_id`)
OR NOT(NEW.`attribute_set_id` <=> OLD.`attribute_set_id`)
OR NOT(NEW.`parent_id` <=> OLD.`parent_id`)
OR NOT(NEW.`created_at` <=> OLD.`created_at`)
OR NOT(NEW.`path` <=> OLD.`path`)
OR NOT(NEW.`position` <=> OLD.`position`)
OR NOT(NEW.`level` <=> OLD.`level`)
OR NOT(NEW.`children_count` <=> OLD.`children_count`)
) THEN INSERT IGNORE INTO `catalog_category_product_cl` (`entity_id`) VALUES (NEW.`entity_id`);
END IF;
END
This trigger was identified using the command SHOW TRIGGERS WHERE Statement LIKE "%catalog_category_product_cl%";
.
Further investigation into the sync process revealed that the children_count
attribute was reset to 0 and then recalculated, resulting in the changelog being updated twice - once for the reset and once for the recount. ~~A pull request addressing this issue is forthcoming.~~ Created in #666
This PR changes how the children_count attribute is managed by relocating its processing to the update code, which wil updates this attribute for new categories only. With this adjustment, if there are no updates, the category's children_count
will no longer be reset to 0.
It will still be recalculated if there is an update with category in Akeneo >
https://github.com/akeneo/magento2-connector-community/blob/6003d331976a59d72729facf1c13a006316d2a31/Job/Category.php#L707-L722
This did create 2 unnecessary changes in the catalog_category_product_cl
changelog table.
Environment and Configuration:
- The system is currently running Akeneo 5, although tests on Akeneo 7 confirmed the issue persists.
- The database in use is MariaDB, version 10.6.12-MariaDB-0ubuntu0.22.04.1.
Steps to Reproduce:
- Create several categories and subcategories.
- Execute the category job sync to Magento 2 using the connector.
- Reindex Category Products.
- Initiate a new sync with the Akeneo connector for the category job, without making any changes.
Expected Result:
- The indexer should not register any changes.
Actual Result:
- The "Category Products" indexer is again populated with changes, despite no actual modifications being made.
Fix for this in PR #666
@magentix Can you have a look? and merge this because we still experience this. I have fixed this with a composer patch but it will be really nice if this is fixed in the official repo.