Skip to content

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

Merged
SchrodingersGat merged 1 commit into
inventree:masterfrom
eeintech:stock_to_build_prefetch
Sep 22, 2020
Merged

SchrodingersGat merged 1 commit into
inventree:masterfrom
eeintech:stock_to_build_prefetch

Conversation

@eeintech

Copy link
Copy Markdown
Contributor

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

@SchrodingersGat

Copy link
Copy Markdown
Member

Have you profiled this using the debug toolbar?

@eeintech

Copy link
Copy Markdown
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
Copy Markdown
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