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

Discount query improvements #1109

Merged
merged 7 commits into from
Jul 6, 2023
Merged

Conversation

alecritson
Copy link
Collaborator

Based on #1103 this PR looks to optimise the query when fetching discounts. Beforehand we just loaded all available discounts, regardless of whether they were actually needed and then left it up to the individual types to figure out whether they should apply, this will be quite taxing on sites with large amounts of discounts. This PR looks to change the following:

  • Removed the custom logic for checking customer groups / channels in favour of the recently added scopes.
  • Added usable scope to discounts so we can query based on whether uses has exceeded max_uses if present.
  • Added products scope to discounts to query based on whether the discount is limited to certain product ids.
  • The Discounts::getDiscounts() method now accepts a nullable Cart model to be passed.
  • If the cart exists, we only fetch discounts which have the products in the cart is conditions or no conditions at all.
  • If the cart has a coupon, we only fetch discounts which match that coupon, or if the discount requires no coupon.

This PR relies on the tweak on #1108

@vercel
Copy link

vercel bot commented Jun 22, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lunar-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 6, 2023 7:28am

@glennjacobs
Copy link
Contributor

@alecritson looks good, much tidier.

@alecritson alecritson merged commit 24d40e0 into main Jul 6, 2023
12 checks passed
@alecritson alecritson deleted the hotfix/discount-query-improvements branch July 6, 2023 10:06
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.

2 participants