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

Reduced SQL load for 'Require Stock to Complete Build' widget on homepage #995

Merged
merged 1 commit into from
Sep 22, 2020

Conversation

eeintech
Copy link
Contributor

Follow-up of #984 (2 SQL queries vs N+1 for build related items)

@SchrodingersGat
Copy link
Member

Have you profiled this using the debug toolbar?

@eeintech
Copy link
Contributor Author

Oh yeah I should have mentioned this!

I have 21 parts in my database. I tested with following URL: /api/part/?stock_to_build=true

With the original code, I had 20 similar queries regarding build items fetching.
With this code, those 20 similar queries are gone and the number of SQL queries went down by 19.

However, the potentially redundant stock item queries are not eliminated. It's a bit more complex as the prefetch_related is embedded in the Part.can_build property method.
But the subset of parts is greatly reduce by the time it reaches this step, so I don't see any major hiccup here.

@SchrodingersGat
Copy link
Member

Nice, thanks for implementing this and testing it :)

@SchrodingersGat SchrodingersGat merged commit 7dd988a into inventree:master Sep 22, 2020
@eeintech eeintech deleted the stock_to_build_prefetch branch July 14, 2021 19:10
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