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

Improve performance of Taxon promotion rule #1409

Closed
wants to merge 1 commit into from
Closed

Improve performance of Taxon promotion rule #1409

wants to merge 1 commit into from

Conversation

mtomov
Copy link
Contributor

@mtomov mtomov commented Aug 29, 2016

  1. 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.

  2. 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)

  3. Fix incorrect test on #eligible?#all for taxon child of a taxon rule
    case.

    • there were no children tested in the case
  4. On #eligible?#all, take only the IDs from the DB to
    reduce memory overhead

On a next PR, I will see to fix #actionable? to perform matching with the rule's descendant taxons.

@jhawthorn
Copy link
Contributor

These changes look good and make sense to me 👍

However I'm a little confused about the existing behaviour of this class. eligible? checks the configured taxons and all descendants, actionable? only seems to check against the taxons themselves (not children)

@mtomov
Copy link
Contributor Author

mtomov commented Aug 29, 2016

That's right. I believe it's a big oversight on #actionable?, so I will see to fix this bug in the next PR after this refactor.

@jrochkind
Copy link
Contributor

jrochkind commented Aug 29, 2016

I've run into other inconsistencies with how actionable? works, I think when it was added to spree it was done a bit sloppily. I previously PR'd a fix that actionable? didn't pay attention the boolean bit for promotion-eligible, but eligible? did. Some of this stuff is behind the general lack of reliability people find with line-item-specific things on promotions.

  1) 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.


  2) 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)


  3) Fix incorrect test on #eligible?#all for taxon child of a taxon rule
     case.

     * there were no children tested in the case


  4) On #eligible?#all, take only the IDs from the DB to
     reduce memory overhead
@mtomov
Copy link
Contributor Author

mtomov commented Mar 28, 2017

Hello,

I have resurrected this PR with improved variable names, and a few more details polished. I still believe it's a good addition.

I think the review focus should really be on the only test, which I have modified - I believe that it was incorrectly written in first place, and wasn't actually testing what we wanted.

Other than that, given that the code is not too convoluted, the other tests should server their role to ensure that I haven't broken anything with those changes.

Copy link
Contributor

@cbrunsdon cbrunsdon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, sorry it took us so long to get to, really appreciate the change 👍

@gmacdougall
Copy link
Member

Thanks for the work on this Martin. Sorry for the slow response, but we agree that we like this code and I have rebased it with intent to merge in #2258

👍

@gmacdougall gmacdougall closed this Oct 4, 2017
@mtomov
Copy link
Contributor Author

mtomov commented Oct 4, 2017

Hey, no problem at all, glad you took the time to look at it as it can be quite confusing what is going on there. Thanks!

@mtomov mtomov deleted the improve-performance-of-taxon-rule branch October 4, 2017 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants