perf(db): add composite indexes for memory recency and per-user practice results#83
Open
tongshu2023 wants to merge 1 commit into
Open
perf(db): add composite indexes for memory recency and per-user practice results#83tongshu2023 wants to merge 1 commit into
tongshu2023 wants to merge 1 commit into
Conversation
…ice results (zijinz456#31) - conversation_memories gains (user_id, course_id, created_at) so recency-ordered memory lookups stop full-scanning past 10K records; the existing (user_id, course_id) index stays for planner choice on non-ordered lookups. - practice_results gains (user_id, problem_id) for per-user answer history (mastery and wrong-answer queries). - Alembic migration 20260610_0025 (house style: inspector-guarded create/drop, sqlite early-return since env.py skips Alembic there and create_all picks the indexes up from the models). Single head verified via alembic heads. - tests/test_model_indexes.py pins both index definitions in metadata. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #31.
Changes
conversation_memoriesgains the composite index(user_id, course_id, created_at)— recency-ordered memory lookups (WHERE user_id/course_id ... ORDER BY created_at) stop full-scanning past 10K records. The existing(user_id, course_id)index is kept for planner choice on non-ordered lookups.practice_resultsgains(user_id, problem_id)for per-user answer history (mastery and wrong-answer queries). The table previously had no secondary indexes at all.20260610_0025in the house style: inspector-guarded create/drop, early return on SQLite (env.pyskips Alembic for sqlite URLs; the local schema picks the indexes up from the models viacreate_all).alembic headsverified single-head.tests/test_model_indexes.pypins both index definitions in the SQLAlchemy metadata so they can't silently disappear.Heads-up for the merge queue
PR #79 (FK ondelete rules, also branched from current
main) adds migration20260610_0024with the samedown_revision. Whichever PR merges second needs a one-linedown_revisionbump to keep a single head — happy to rebase this one if #79 lands first.Tests
test_model_indexes.py + test_loom.py: 39 passed locally; migration compiles andalembic headsshows a single head.Acceptance criteria
🤖 Generated with Claude Code