-
Notifications
You must be signed in to change notification settings - Fork 462
Description
Is your feature request related to a problem? Please describe.
There seems to be some optimisation problems with how the Currency and Price system 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:
- Querying the
currencyof thePrice:
https://github.com/lunarphp/lunar/blob/main/packages/core/src/Base/Casts/Price.php#L39 - Querying the
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
