Skip to content

perf(db): add saves favorites ordering index#940

Merged
raymondjacobson merged 1 commit into
mainfrom
codex/saves-library-order-index
Jun 9, 2026
Merged

perf(db): add saves favorites ordering index#940
raymondjacobson merged 1 commit into
mainfrom
codex/saves-library-order-index

Conversation

@raymondjacobson

Copy link
Copy Markdown
Member

Summary

  • add a partial concurrent index for active track saves by user
  • order the index by (user_id, blocknumber, save_item_id DESC) to match /v1/users/:id/favorites pagination
  • include created_at because the endpoint returns it from saves

Evidence

  • prod read-only pg_stat_statements showed the favorites/library saves pagination query at roughly 24.7M calls, ~1.0M total seconds, and ~6TB temp I/O
  • the hot SQL is in api/v1_users_favorites.go and filters save_type = 'track', is_current = true, is_delete = false, user_id = ?, then orders by saves.blocknumber, saves.save_item_id DESC\n- existing saves_user_idx (user_id, save_type, save_item_id, is_delete) can filter by user/type but cannot satisfy the blocknumber ordering, forcing a sort for paginated responses\n- checked prod in read-only mode; HypoPG is not installed, so this PR cannot include a hypothetical index EXPLAIN without creating anything on prod\n\n## Test Plan\n- git diff --cached --check before commit\n- migration-only change

@raymondjacobson raymondjacobson merged commit dfb9280 into main Jun 9, 2026
5 checks passed
@raymondjacobson raymondjacobson deleted the codex/saves-library-order-index branch June 9, 2026 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant