Add entries(project_id, created_at DESC) index for the project-scoped list query #95
Labels
No labels
bug
duplicate
enhancement
future
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
rbrooks/TeaLeaves#95
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Severity: Medium · Confidence: High · Effort: XS · Category: code (performance)
Evidence
api/src/db/migrations/002_entries_tags_audit.sql:19-23- indexes lead withuser_id;026_projects.sql:119- partialdeleted_atindex only.api/src/routes/entries.ts:73-77,85,187-193,321-WHERE e.project_id = (${ACTIVE_PROJECT_SQL}) . ORDER BY e.created_at DESC.Problem
v4 made
project_idthe scoping column for every list view, but the indexes still lead withuser_id. The hottest query in the app (entry list, filtered by project + sorted by created_at) has no index serving its filter+sort.Impact
Sequential scan + sort on entry listing as data grows; degrades the primary UI. Latent - bites at scale (a long-running research project).
Fix
Migration 044:
CREATE INDEX entries_project_created_idx ON entries (project_id, created_at DESC) WHERE deleted_at IS NULL;and consider one on
motifs(project_id).Acceptance criteria
Filed from the 2026-07-15 codebase audit. Full report:
docs/.internal/report-2026-07-15.md(gitignored).Fixed in
c1ed843(v7.2.0 wave 2).Migration
045_project_scoped_indexes.sql(not 044 — that number went to #98 in wave 1):Leads with
project_id(equality), thencreated_at DESC(the sort), partial ondeleted_at IS NULLto match the query exactly and stay small. Took the "consider one onmotifs(project_id)" suggestion too.Acceptance criteria:
Verified on dev after deploy — migration applied
✓, and the planner picks it with no Sort node (the index supplies the ordering):CI green (242/242).