Optimize notification timestamp pagination#988
Merged
Conversation
raymondjacobson
added a commit
that referenced
this pull request
Jul 7, 2026
## Summary - Bound unread notification polling to the newest 25k single-recipient and 25k multi-recipient candidates before grouping. - Bound first-page and timestamp notification reads to newest candidate groups, then cap expensive validation/JSON aggregation to the newest 100 actions per selected group. - Reuse the read-only transaction with scoped `SET LOCAL enable_seqscan = off` for candidate-limited notification reads, including unread polling. ## Why - Today after PR #988, the remaining failures shifted to first-page `limit=20` and unread `limit=0`, not just timestamp pagination. - Since midnight Pacific on 2026-07-07, Cloud Logging showed 49 `notifications unread query timed out` and 13 `notifications query timed out` messages. - The hot first page for `eJ57D` includes giant groups: roughly 11.7k `save:4281:type:playlist` rows and 12.3k `follow:51` rows inside the newest candidate groups. Candidate rows alone were still too many for the full validation/aggregation stack. ## Live validation - Bounded unread query for `eJ57D` returned count 20 in ~0.6s. - First-page candidate rows without action capping still timed out under the 8s statement timeout when the full filter stack was included. - First-page full filter stack with newest 100 actions per selected group returned a full 20-group page in ~0.42s. ## Product impact - Very large notification groups now return the newest 100 actions for that group in candidate-limited reads instead of trying to return thousands of action rows. - The endpoint still returns the same response shape and group ordering, but giant grouped notifications may include fewer action objects. ## Test plan - `go test ./api -run ^'$'`\n- Attempted `go test ./api -run TestV1Notifications`; blocked locally because the test DB at `localhost:21300` is not running.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SET LOCAL enable_seqscan = offso the multi-recipient candidate branch uses the partial GIN path instead of the bad sequential scan plan.Live evidence
notifications query timed out), not unread polling.user_id=51,timestamp=1783054526.961588), the unbounded full page timed out under the 8s read guard.Test plan
go test ./api -run ^'$'