Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions api/v1_users_comments.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import (
func (app *ApiServer) v1UsersComments(c *fiber.Ctx) error {

sql := `
SELECT comment_id as id
FROM comments
LEFT JOIN comment_threads USING (comment_id)
WHERE user_id = @user_id
AND entity_type = 'Track'
AND comments.is_delete = false
`
SELECT comment_id as id
FROM comments
WHERE user_id = @user_id
AND entity_type = 'Track'
AND comments.is_delete = false
`

args := pgx.NamedArgs{
"user_id": app.getUserId(c),
Expand Down
14 changes: 14 additions & 0 deletions ddl/migrations/0224_comments_user_track_created_at_idx.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- Supports /v1/users/:id/comments pagination:
--
-- WHERE user_id = ?
-- AND entity_type = 'Track'
-- AND is_delete = false
-- ORDER BY created_at DESC
--
-- Without this index, the endpoint scans and sorts the full comments table for
-- every user-comments page request.
CREATE INDEX CONCURRENTLY IF NOT EXISTS comments_user_track_created_at_idx
ON public.comments USING btree (user_id, created_at DESC)
INCLUDE (comment_id)
WHERE entity_type = 'Track'
AND is_delete = false;
Loading