mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-03-06 05:33:11 -05:00
Remove all sqlalchemy lazy-loading from app (#2260)
* Remove some implicit lazy-loads from user serialization * implement full backup restore across different database versions * rework all custom getter dicts to not leak lazy loads * remove some occurances of lazy-loading * remove a lot of lazy loading from recipes * add more eager loading remove loading options from repository remove raiseload for checking * fix failing test * do not apply loader options for paging counts * try using selectinload a bit more instead of joinedload * linter fixes
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from pydantic import UUID4, Field
|
||||
from sqlalchemy.orm import selectinload
|
||||
from sqlalchemy.orm.interfaces import LoaderOption
|
||||
|
||||
from mealie.schema._mealie import MealieModel
|
||||
|
||||
from ...db.models.recipe import RecipeIngredientModel, RecipeInstruction, RecipeModel, RecipeShareTokenModel
|
||||
from .recipe import Recipe
|
||||
|
||||
|
||||
@@ -33,3 +36,26 @@ class RecipeShareToken(RecipeShareTokenSummary):
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
@classmethod
|
||||
def loader_options(cls) -> list[LoaderOption]:
|
||||
return [
|
||||
selectinload(RecipeShareTokenModel.recipe).joinedload(RecipeModel.recipe_category),
|
||||
selectinload(RecipeShareTokenModel.recipe).joinedload(RecipeModel.tags),
|
||||
selectinload(RecipeShareTokenModel.recipe).joinedload(RecipeModel.tools),
|
||||
selectinload(RecipeShareTokenModel.recipe).joinedload(RecipeModel.nutrition),
|
||||
selectinload(RecipeShareTokenModel.recipe).joinedload(RecipeModel.settings),
|
||||
selectinload(RecipeShareTokenModel.recipe).joinedload(RecipeModel.assets),
|
||||
selectinload(RecipeShareTokenModel.recipe).joinedload(RecipeModel.notes),
|
||||
selectinload(RecipeShareTokenModel.recipe).joinedload(RecipeModel.extras),
|
||||
selectinload(RecipeShareTokenModel.recipe).joinedload(RecipeModel.comments),
|
||||
selectinload(RecipeShareTokenModel.recipe)
|
||||
.joinedload(RecipeModel.recipe_instructions)
|
||||
.joinedload(RecipeInstruction.ingredient_references),
|
||||
selectinload(RecipeShareTokenModel.recipe)
|
||||
.joinedload(RecipeModel.recipe_ingredient)
|
||||
.joinedload(RecipeIngredientModel.unit),
|
||||
selectinload(RecipeShareTokenModel.recipe)
|
||||
.joinedload(RecipeModel.recipe_ingredient)
|
||||
.joinedload(RecipeIngredientModel.food),
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user