Skip to content

Currency bottleneck - having multiple currencies drastically increases query count #760

@JordiBaguette

Description

@JordiBaguette

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:
image
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):
image
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:

image

A possible solution might be to eager-load the prices and currencies.

Describe alternatives you've considered

N/A

Additional context

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions