[Perf] Bundle related entities in /v1/notifications response#799
Open
dylanjeffers wants to merge 2 commits intomainfrom
Open
[Perf] Bundle related entities in /v1/notifications response#799dylanjeffers wants to merge 2 commits intomainfrom
dylanjeffers wants to merge 2 commits intomainfrom
Conversation
Avoid N+1 client round trips by hydrating users/tracks/playlists referenced by notification action data inline under a `related` key, matching the pattern used by the comments endpoints. To prevent fan-out groups (e.g. one notification representing 100 new followers) from bloating the payload, we mine actor IDs from at most 3 actions per group; target entity IDs are duplicated across every action so the cap doesn't drop them. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Clients render a single avatar per notification group, so hydrating more actors just bloats the response. Targets are unaffected — they repeat across every action in a group, so the first action still carries them. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
/v1/notificationsaction data inline under a newrelatedblock, eliminating the N+1 client round trips currently needed to render notifications.app.queries.Parallel(...)+data/relatedenvelope).*_item_id,content_id, commententity_id) are routed to tracks vs. playlists by their sibling discriminator (type/content_type/entity_type).relatedkeep working.Test plan
go build ./...andgo vet ./api/...cleanTestV1Notifications_RelatedEntities(covers hydration of users, tracks, playlists; asserts the per-group actor cap bounds a 5-follower fan-out group)TestV1Notifications*suite (response is purely additive — existing assertions ondata.notifications.*should still pass)/v1/notifications/{me}and confirmrelated.users,related.tracks,related.playlistspopulate for follow / repost / save / comment / tip notificationsNotes
IncludeUnlisted: truefor the parallel hydration — notifications are recipient-personal and may legitimately reference unlisted tracks the user has a relationship with.entity_idis folded intorelated.tracksonly whenentity_type == "Track". TheFanClubandEvententity types don't have a hydrator inParalleltoday; clients can keep round-tripping for those until we wire them in.🤖 Generated with Claude Code