Currency bottleneck - having multiple currencies drastically increases query count #1050
JordiBaguette
started this conversation in
Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Is your feature request related to a problem? Please describe.
There seems to be some optimisation problems with how the
CurrencyandPricesystem is currently implemented.I pulled down a clean version of the Lunar demo store and installed everything according to the documentation provided in the
README.md. The only thing I did was add the Laravel Debugbar to it to verify and view the queries being executed.When viewing a collection page these are the queries that are being executed with all the default seeding:

Right now for a collection page containing 4 products, with the one default currency, there are 65 queries.
When I add more currencies and create prices for them (see commit: GameCoda/lunarphp-currency-bottleneck@e271b7d):

After adding 13 more currencies, the query count went up from 65 queries to 663 queries on an - apart from the additional currencies - identical setup.
Test repository: lunarphp-currency-bottleneck
Possible related issue: #264
The Price model casting creates a big bottleneck.Describe the solution you'd like
It appears that the duplicate queries are coming from:
currencyof thePrice:https://github.com/lunarphp/lunar/blob/main/packages/core/src/Base/Casts/Price.php#L39
unit quantityof thePriceable:https://github.com/lunarphp/lunar/blob/main/packages/core/src/Base/Casts/Price.php#L23
A possible solution might be to eager-load the prices and currencies.
Describe alternatives you've considered
N/A
Additional context
N/A
Beta Was this translation helpful? Give feedback.
All reactions