Fix price indexation loop stopping early with non-sequential product ids - #1258
Open
boo-code wants to merge 1 commit into
Open
Fix price indexation loop stopping early with non-sequential product ids#1258boo-code wants to merge 1 commit into
boo-code wants to merge 1 commit into
Conversation
indexPrices() used $cursor (the last indexed id_product returned by indexPricesUnbreakable()) as the do/while continuation check against $nbProducts (the number of products to index). Since product ids are not necessarily sequential and are commonly larger than the product count (gaps left by deleted, imported or migrated products), $cursor < $nbProducts becomes false as soon as an indexed id exceeds the count, so the batching loop stops after very few iterations and the work falls back to one 100-row batch per recursion/AJAX call. On large catalogues this both slows full indexation dramatically and deepens the indexPrices() self-recursion. Compare the real progress counter instead.
|
Hello @boo-code! This is your first pull request on ps_facetedsearch repository of the PrestaShop project. Thank you, and welcome to this Open Source community! |
kpodemski
approved these changes
Jul 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
indexPrices()used$cursoras thedo/whilecontinuation check:$cursor < $nbProducts. But$cursoris the last indexedid_productreturned byindexPricesUnbreakable()(return (int) $lastIdProduct;), not a progress counter — while$nbProductsis the number of products to index. Product ids are not sequential and are routinely larger than the product count (gaps from deleted / imported / migrated products), so$cursor < $nbProductsflips to false as soon as an indexed id exceeds the count. The batching loop then stops after very few iterations and indexation falls back to a single 100-row batch perindexPrices()self-recursion (CLI/cron) or per AJAX round-trip (BO "rebuild index"). On large catalogues this both slows full indexation dramatically and deepens theindexPrices()recursion (one level per 100 products). The method already maintains$indexedProducts += $length;, which is the real progress counter, so the loop now compares against that instead.id_productis greater than the number of indexable products (e.g. delete/migrate products so ids are sparse, or simply have more than ~100 products with non-contiguous ids), rebuild the faceted-search price index (BO > module configuration, orConfiguration::updateValue('PS_LAYERED_INDEXED', 0)then trigger indexing). Before: thelayered_price_indextable is filled only in small steps (one 100-row batch per call), and on large/sparse catalogues full indexation is slow or doesn't complete within the recursion/limits. After: each call batches until the time/memory limit is reached and the table is fully populated.Notes on verification
indexPrices()/indexPricesUnbreakable()areprivatemethods on the mainPs_facetedsearchmodule class, which currently has no unit-test coverage (the suite targets thesrc/classes), and they are tightly coupled to the database. I verified the fix by tracing the code rather than with a mock-heavy reflection test:indexPricesUnbreakable()returns$lastIdProduct(an id, confirmed), and$indexedProductsincrements by$lengthper batch, so$indexedProducts < $nbProductsis the correct continuation condition. It is monotonic (no infinite-loop risk) and the existing memory /max_execution_time/$cursor == 0guards are untouched. Happy to add a test if you have a preferred pattern for covering the module class.