Skip to content

Add comments user pagination index#970

Merged
raymondjacobson merged 1 commit into
mainfrom
codex/comments-user-created-at-index
Jun 23, 2026
Merged

Add comments user pagination index#970
raymondjacobson merged 1 commit into
mainfrom
codex/comments-user-created-at-index

Conversation

@raymondjacobson

Copy link
Copy Markdown
Member

Summary

  • add a concurrent partial covering index for /v1/users/:id/comments pagination
  • remove an unused comment_threads join from the user-comments id page query
  • keep hydration/filtering behavior in FullComments unchanged

DB evidence

Read-only investigation against discovery-1-replica showed this route is currently dominating the read replica.

Live 60-second pg_stat_statements delta:

  • SELECT comment_id as id FROM comments ... WHERE user_id = $1 ... ORDER BY comments.created_at DESC LIMIT/OFFSET
  • 1,610 calls in 60s
  • ~1,666,937 ms accumulated DB execution time
  • ~1,035 ms mean execution time

Post-rollout 30-second delta still showed ongoing pressure:

  • 954 calls in 30s
  • ~986,306 ms accumulated DB execution time
  • ~1,034 ms mean execution time

Representative EXPLAIN (ANALYZE, BUFFERS) on the replica:

  • user 527480232, LIMIT 10 OFFSET 0: ~1.07s
  • user 20, LIMIT 10 OFFSET 0: ~1.05s
  • user 527480232, LIMIT 10 OFFSET 1000: ~1.08s

The plan scans the full comments table, hashes comment_threads, sorts, and returns only a page of ids. Catalog check showed comments only had comments_pkey and comments_blocknumber_idx, with no index matching user_id + Track + active + created_at.

Bridge logs also show the live traffic source is IP 162.220.232.107 using app_name=TEMPO, TEMPO_sync, TEMPO_engage, and TEMPO_analytics against /v1/users/:userId/comments.

Test

  • go test ./api -run 'TestUserComments|Test200UnAuthed' -count=1

@raymondjacobson raymondjacobson merged commit 7de9552 into main Jun 23, 2026
5 checks passed
@raymondjacobson raymondjacobson deleted the codex/comments-user-created-at-index branch June 23, 2026 00:08
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.

2 participants