Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Price index limited to 100 product #37918

Open
2 tasks done
jexamd opened this issue Jan 28, 2025 · 4 comments · May be fixed by PrestaShop/ps_facetedsearch#1124
Open
2 tasks done

Price index limited to 100 product #37918

jexamd opened this issue Jan 28, 2025 · 4 comments · May be fixed by PrestaShop/ps_facetedsearch#1124
Assignees
Labels
8.1.x Branch BO Category: Back Office Bug Type: Bug Faceted search Module: ps_facetedsearch Module Module NMI Status: issue needs more information

Comments

@jexamd
Copy link

jexamd commented Jan 28, 2025

Prerequisites

Describe the bug and add attachments

Price indexing loop only one time in indexPricesUnbreakable.
The second times (and next), we compare $cursor value which is the last productId indexed with the number of products to index ($nbProducts).

File : ps_facetedsearch method IndexPrice.

Expected behavior

Compare $cursor with productId and not product count

Steps to reproduce

Launch full index price with product id > 100 in the first loop/

PrestaShop version(s) where the bug happened

8.1.7

PHP version(s) where the bug happened

7.2

If your bug is related to a module, specify its name and its version

ps_facetedsearch 3.16.1

Your company or customer's name goes here (if applicable).

Hastone & Ten

@jexamd jexamd added Bug Type: Bug New New issue not yet processed by QA labels Jan 28, 2025
@SiraDIOP SiraDIOP self-assigned this Jan 29, 2025
@SiraDIOP
Copy link

Hello @jexamd ,

Could you please provide us with more info ?
We need more details to understand how we can reproduce your issue:

  • host
  • server setup and configuration
  • PrestaShop version (source)
  • debug mode report
  • PHP error logs
  • apache error log
  • Javascript console log
  • screenshots
  • ...

You don't know how to get this information? Please read the following article: How to create a bug report.

Thank you

@SiraDIOP SiraDIOP added NMI Status: issue needs more information 8.1.x Branch Waiting for author Status: action required, waiting for author feedback New Products Page Label: Which BO under menu is concerned and removed New New issue not yet processed by QA labels Jan 30, 2025
@florine2623
Copy link
Contributor

Hello @jexamd ,

Could you explicit the steps to reproduce ?

Thanks

@SiraDIOP SiraDIOP added Faceted search Module: ps_facetedsearch Module Module BO Category: Back Office and removed New Products Page Label: Which BO under menu is concerned labels Feb 4, 2025
@Codencode
Copy link
Contributor

The code in question handles the price indexing of products in a PrestaShop module called ps_facetedsearch. The indexing process occurs in a do-while loop, iterating over a set of products and updating a cursor ($cursor) to move between product IDs.

How the Loop Works

  • $cursor: Represents the current product ID being processed.
  • $nbProducts: Represents the total number of products to be indexed.
  • $length: Defines how many products are processed in each iteration (e.g., 100 products at a time).

The loop continues as long as:

  • $cursor < $nbProducts
  • Memory usage does not exceed the allowed limit
  • Execution time does not exceed the maximum allowed time ($maxExecutionTime)

The Problem

The issue arises when the value of $cursor exceeds $nbProducts, causing $cursor < $nbProducts to become false and terminating the loop prematurely. This behavior does not account for:

  1. Gaps in the ID sequence

    • If some products have been deleted, product IDs might not be consecutive (e.g., IDs: 1, 2, 5, 10).
    • $cursor could exceed $nbProducts before processing all actual products.
  2. Maximum ID greater than $nbProducts

    • If the highest product ID in the database is greater than $nbProducts, the loop may stop before processing all products.

Result

  • The loop performs only one iteration at a time (or stops entirely) when $cursor exceeds $nbProducts, leading to incomplete and inefficient indexing.

Example

Given Products:

Product IDs in the database: 1, 2, 3, 5, 10
$nbProducts = 4 (total number of products to be indexed)
$cursor starts at 0 and increments by 100 per iteration.

Current Behavior:

  1. First iteration: $cursor = 100 (processes products with IDs from 1 to 100).
  2. Since $cursor (100) > $nbProducts (4), the loop terminates.
  3. Products with IDs 5 and 10 are never processed.

Expected Behavior:

  • The loop should continue until all products, including the one with the maximum ID (10), have been processed.

Impact on AJAX Calls

The indexing process runs via AJAX calls, meaning the script is invoked multiple times to process products in chunks. Due to premature termination:

  • Additional AJAX calls: Each time the loop stops prematurely, a new AJAX call is required, increasing overhead.
  • Inefficiency: Gaps in product IDs cause the loop to stop and restart multiple times, processing fewer products than possible per iteration.
  • Longer execution time: More AJAX calls mean increased processing time due to repeated script initializations and database queries.

The solution would be to replace:

Modifica
$cursor < $nbProducts
with
$cursor < $maxProductId
here: https://github.com/PrestaShop/ps_facetedsearch/blob/e3d8f332b60a116a4e4c054a746a4df201f02621/ps_facetedsearch.php#L1581-L1585

Obviously, $maxProductId needs to be retrieved.

@Codencode
Copy link
Contributor

This is my solution: PrestaShop/ps_facetedsearch#1124

@paulnoelcholot paulnoelcholot removed the Waiting for author Status: action required, waiting for author feedback label Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.1.x Branch BO Category: Back Office Bug Type: Bug Faceted search Module: ps_facetedsearch Module Module NMI Status: issue needs more information
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants