mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-08-03 04:25:24 +02:00
* 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
73 lines
1.4 KiB
Python
73 lines
1.4 KiB
Python
from pydantic import UUID4
|
|
from sqlalchemy.orm import selectinload
|
|
from sqlalchemy.orm.interfaces import LoaderOption
|
|
|
|
from mealie.db.models.recipe import RecipeModel, Tag
|
|
from mealie.schema._mealie import MealieModel
|
|
|
|
|
|
class CategoryIn(MealieModel):
|
|
name: str
|
|
|
|
|
|
class CategorySave(CategoryIn):
|
|
group_id: UUID4
|
|
|
|
|
|
class CategoryBase(CategoryIn):
|
|
id: UUID4
|
|
slug: str
|
|
|
|
class Config:
|
|
orm_mode = True
|
|
|
|
|
|
class CategoryOut(CategoryBase):
|
|
slug: str
|
|
group_id: UUID4
|
|
|
|
class Config:
|
|
orm_mode = True
|
|
|
|
|
|
class RecipeCategoryResponse(CategoryBase):
|
|
recipes: "list[RecipeSummary]" = []
|
|
|
|
class Config:
|
|
orm_mode = True
|
|
|
|
|
|
class TagIn(CategoryIn):
|
|
pass
|
|
|
|
|
|
class TagSave(TagIn):
|
|
group_id: UUID4
|
|
|
|
|
|
class TagBase(CategoryBase):
|
|
pass
|
|
|
|
|
|
class TagOut(TagSave):
|
|
id: UUID4
|
|
slug: str
|
|
|
|
class Config:
|
|
orm_mode = True
|
|
|
|
|
|
class RecipeTagResponse(RecipeCategoryResponse):
|
|
@classmethod
|
|
def loader_options(cls) -> list[LoaderOption]:
|
|
return [
|
|
selectinload(Tag.recipes).joinedload(RecipeModel.recipe_category),
|
|
selectinload(Tag.recipes).joinedload(RecipeModel.tags),
|
|
selectinload(Tag.recipes).joinedload(RecipeModel.tools),
|
|
]
|
|
|
|
|
|
from mealie.schema.recipe.recipe import RecipeSummary # noqa: E402
|
|
|
|
RecipeCategoryResponse.update_forward_refs()
|
|
RecipeTagResponse.update_forward_refs()
|