From 0ba96341316ef23a836ba3bee7dbba09066aebd0 Mon Sep 17 00:00:00 2001 From: jableader Date: Sat, 1 Nov 2025 21:25:18 +1100 Subject: [PATCH] Remove legacy cookie auth and Person-based recipe helper; add composite indices; spec updated --- backend-spec.md | 2 +- main.py | 2 +- meals/repository.py | 4 ++++ recipes/repository.py | 4 ++++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/backend-spec.md b/backend-spec.md index 100054c..e6f1de6 100644 --- a/backend-spec.md +++ b/backend-spec.md @@ -201,7 +201,7 @@ Route surface lockdown: - ✅ **Acceptance (initial)**: Added `tests/test_migration_households.py` covering: new tables exist, `household_id` columns exist, default household created, and data porting from `Person` to `User` and `HouseholdMember`. Full test suite passes. - Pending follow-ups for this step: - - Add composite indices `(household_id, id)` where high-cardinality pagination will benefit. + - (Done) Add composite indices `(household_id, id)` where high-cardinality pagination will benefit (Recipe, Meal). - Extend migration to add FK constraints from tenant tables to `Household(id)` where safe. - Plan and implement data backfill for cross-table references once `users` replace `persons` in code. - Ensure fresh bootstraps include `household_id` in all tenant table DDL (now updated for Ingredient, Recipe, Meal, ShoppingList, ShoppingListItem). diff --git a/main.py b/main.py index 3f75d93..4a95e7f 100644 --- a/main.py +++ b/main.py @@ -192,4 +192,4 @@ app = create_app() DATABASE_PATH = settings.database_path -# get_db, cookie_person, and error_response are imported from api.deps +# get_db and error_response are imported from api.deps diff --git a/meals/repository.py b/meals/repository.py index 20be394..404cdbe 100644 --- a/meals/repository.py +++ b/meals/repository.py @@ -58,6 +58,10 @@ async def create(conn): await conn.execute( "CREATE INDEX IF NOT EXISTS idx_meal_recipes_meal_id ON MealRecipe(meal_id);" ) + # Composite index for household-scoped pagination/lookups + await conn.execute( + "CREATE INDEX IF NOT EXISTS idx_meal_household_id_id ON Meal(household_id, id);" + ) async def insert_meal_participant(conn, meal_id: int, person_id: int, role: str): diff --git a/recipes/repository.py b/recipes/repository.py index 90825d5..83a663b 100644 --- a/recipes/repository.py +++ b/recipes/repository.py @@ -36,6 +36,10 @@ async def create(conn): await conn.execute( "CREATE INDEX IF NOT EXISTS idx_recipe_name_hidden_id ON Recipe(name, date_hidden, id);" ) + # Composite index for fast household-scoped pagination + await conn.execute( + "CREATE INDEX IF NOT EXISTS idx_recipe_household_id_id ON Recipe(household_id, id);" + ) def _as_insert_field(recipe: Recipe, name: str):