Skip to content

Commit 0247f66

Browse files
dylanjeffersclaude
andauthored
Bound /v1/notifications initial load to last 90 days (#761)
Heavy users saw /v1/notifications/:id p50 ~2.2s (max 8.9s) because the query had no upfront time bound on the initial load path — the planner had to materialize every notification matching user_ids, run per-row EXISTS checks and joins, then group/sort/limit at the very end. On the initial load (timestamp_offset=0 AND group_id_offset='') bound n.timestamp to the last 90 days. Pagination (timestamp_offset > 0) stays unbounded so scrolling further back still works. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c6c86d7 commit 0247f66

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

api/v1_notifications.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,10 @@ WHERE
185185
)
186186
)
187187
AND (
188-
(@timestamp_offset = 0 AND @group_id_offset = '') OR
188+
-- Initial load: bound to the last 90 days so heavy users don't fan out
189+
-- over their entire notification history. Pagination (timestamp_offset > 0)
190+
-- is unbounded so scrolling further back still works.
191+
(@timestamp_offset = 0 AND @group_id_offset = '' AND n.timestamp > (now()::timestamp - interval '90 days')) OR
189192
(@timestamp_offset = 0 AND @group_id_offset != '' AND n.group_id < @group_id_offset) OR
190193
(@timestamp_offset > 0 AND n.timestamp < to_timestamp(@timestamp_offset)) OR
191194
(

0 commit comments

Comments
 (0)