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 Spree::Order::NumberGenerator speed #4722

Conversation

RyanofWoods
Copy link
Contributor

@RyanofWoods RyanofWoods commented Nov 17, 2022

Summary

When generating a number, if it already exists, the length of numbers will be increased if over half of the possible options are already taken. Calculating the count of orders is very expensive when having millions of records. Upon multiple number collisions, this SQL becomes a bottleneck.

Checklist

Check out our PR guidelines for more details.

The following are mandatory for all PRs:

  • I have written a thorough PR description.
  • I have kept my commits small and atomic.
  • I have used clear, explanatory commit messages.

The following are not always needed (cross them out if they are not):

  • I have added automated tests to cover my changes.
    - [ ] I have attached screenshots to demo visual changes.
    - [ ] I have opened a PR to update the guides.
    - [ ] I have updated the README to account for my changes.

@github-actions github-actions bot added the changelog:solidus_core Changes to the solidus_core gem label Nov 17, 2022
@codecov
Copy link

codecov bot commented Nov 17, 2022

Codecov Report

Merging #4722 (4cce19a) into master (1fe96cc) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #4722   +/-   ##
=======================================
  Coverage   86.12%   86.12%           
=======================================
  Files         577      577           
  Lines       14640    14643    +3     
=======================================
+ Hits        12608    12612    +4     
+ Misses       2032     2031    -1     
Impacted Files Coverage Δ
core/app/models/spree/order/number_generator.rb 100.00% <100.00%> (+6.66%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@waiting-for-dev waiting-for-dev added the type:enhancement Proposed or newly added feature label Nov 17, 2022
Copy link
Contributor

@waiting-for-dev waiting-for-dev left a comment

Choose a reason for hiding this comment

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

Thanks, @RyanofWoods! ❤️

When generating a number, if it already exists, the length of numbers
will be increased if over half of the possible options are already
taken. This query is very expensive when having millions of records.
Upon multiple number collisions, this SQL becomes a bottleneck.

Co-authored-by: Sung <sung@meundies.com>
@RyanofWoods RyanofWoods force-pushed the ryanofwoods/improve-order-number-generator-speed branch from 758583e to 4cce19a Compare November 17, 2022 09:00
@RyanofWoods
Copy link
Contributor Author

No problem @waiting-for-dev , thanks for MeUndies for discovering this ❤️

I just pushed again as I added some specs.

Copy link
Contributor

@forkata forkata left a comment

Choose a reason for hiding this comment

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

Thanks for porting this over @RyanofWoods 🎉

Copy link
Member

@jarednorman jarednorman left a comment

Choose a reason for hiding this comment

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

But what if I never restart my application?

@waiting-for-dev waiting-for-dev merged commit d582f54 into solidusio:master Nov 21, 2022
@RyanofWoods
Copy link
Contributor Author

But what if I never restart my application?

I don't understand, what's your point? @jarednorman 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:solidus_core Changes to the solidus_core gem type:enhancement Proposed or newly added feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants