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

fix performance issues on /api/foods #2163

Merged

Conversation

fleshgolem
Copy link
Contributor

What type of PR is this?

  • bug

What this PR does / why we need it:

As mentioned in discord, the /api/foods endpoint can be pretty slow if you have a larger number of foods and especially if you use the extras feature for foods. I identified two causes for this:

  1. Any repository that just uses RepositoryGeneric's page_all functionality without modifications can not make use of eager-loading and if there are relations used in the response (i.e. label and extras in this case), they will all be lazy-loaded for any given entry
  2. IngredientFood's getter_dict override was kinda terrible, because the line **GetterDict(name_orm) would cause pydantic to try and resolve ALL model relationships, even if they are not used in the response, causing even more lazy-loading

To improve on this, I added a query_options function to RepositoryGeneric, so every sub-repository can specify its own loading options, if needed. Additionally I rewrote the getter_dict override so it just does the thing it is supposed to do and not cause any more unnecessary loading

Which issue(s) this PR fixes:

No issue filed

Testing

Ran all the tests and tried everything manually

Release Notes

* Improve performance for loading foods on search page

@hay-kot
Copy link
Collaborator

hay-kot commented Feb 22, 2023

To improve on this, I added a query_options function to RepositoryGeneric, so every sub-repository can specify its own loading options, if needed.

Very slick. Love this!

@hay-kot hay-kot merged commit 9d35b09 into mealie-recipes:mealie-next Feb 22, 2023
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