Skip to content

Optimize best-seller category SQL to prefilter products#929

Merged
CySSoO merged 1 commit intomasterfrom
cyssoo/optimize-sql-query-for-better-performance
Feb 2, 2026
Merged

Optimize best-seller category SQL to prefilter products#929
CySSoO merged 1 commit intomasterfrom
cyssoo/optimize-sql-query-for-better-performance

Conversation

@CySSoO
Copy link
Contributor

@CySSoO CySSoO commented Feb 2, 2026

Motivation

  • Reduce database work and integration cost by avoiding expensive joins over all products when computing best-sellers for a category.
  • Improve query planner efficiency by prefiltering active category products before aggregating order details.

Description

  • Rewrote the best-seller-by-category SQL in src/Service/EverblockTools.php to join orders -> order_detail and then inner-join a derived subquery (filtered_products) that preselects product_shop rows joined with category_product filtered by id_shop, active, and id_category.
  • Removed the direct joins to product_shop and category_product from the main query and moved their filtering into the subquery while preserving o.id_shop, o.valid, optional o.date_add filtering, grouping, ordering and limit semantics.
  • Preserved the existing caching behavior (EverblockCache::cacheStore) and SQL escaping for the date condition.

Testing

  • No automated tests were executed for this change.

Codex Task

@CySSoO CySSoO merged commit 140fb2c into master Feb 2, 2026
2 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant