Improve performance of Taxon promotion rule #2258
Merged
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.
Before #actionable? was bringing all product ids of the rule's taxons
from the database. On a particular case in a store with 1mil
products, the promotion was bringing 0.6mil of them, with a query ~ 5sec
and 5mil ids in Ruby.
After, the exists? query is a milliseconds one.
Before #eligible? was fetching all parent taxons of each taxon on a
product, which is not required for the match process.
So, given an order with 10 line items, with each line item having a
product with 3 taxons, each of them having 2 parent taxons
would mean 30 queries to the db to fetch the ancestors, bringing a
total of 60 taxons in Ruby memory.
All of them unnecessary, as the matching processes can be done solely
based on the rule's taxons, which if 5 would mean 5 queries to the DB
(self_and_descendants)
Fix incorrect test on #eligible?#all for taxon child of a taxon rule
case.
On #eligible?#all, take only the IDs from the DB to
reduce memory overhead
This is a rebased version of #1409