Skip to content

[Perf] Use bundled related entities in notifications, drop N+1 fetches#14287

Merged
dylanjeffers merged 3 commits into
mainfrom
claude/zen-ritchie-95cab3
May 11, 2026
Merged

[Perf] Use bundled related entities in notifications, drop N+1 fetches#14287
dylanjeffers merged 3 commits into
mainfrom
claude/zen-ritchie-95cab3

Conversation

@dylanjeffers
Copy link
Copy Markdown
Contributor

Summary

  • The /v1/notifications endpoint now returns a related block ({ users, tracks, playlists }) hydrated server-side (api PR #799). Read those directly to prime the tan-query cache instead of firing N+1 secondary fetches per page.
  • Drops useUsers / useTracks / useCollections prefetch calls from useNotifications, the per-type ID-collection walker, and the last-page hold-back gating.
  • Drops the isAllPending field on the hook result; callers now use the standard isPending directly.

Changes

  • SDK — regenerate NotificationsResponse model with related?: Related (paired with the swagger fix in AudiusProject/api PR for fix/swagger-notifications-related-field). One-file regen diff — no incidental churn.
  • packages/commonuseNotifications rewritten to call primeRelatedData({ related: response.related, queryClient }) once per page. Manual SDK type cast for getNotifications removed (proper type now flows through). primeRelatedData extended to also seed playlists via primeCollectionData.
  • packages/web + packages/mobileNotificationPanel, NotificationPage, NotificationList updated to read isPending directly from the query result.
  • Tooling — fix packages/sdk/rollup.config.ts so npm run build:sdk works on Node 22 (the version pinned by .nvmrc): read package.json via fs.readFileSync (instead of an ESM JSON import, which --configPlugin typescript downlevels to the unsupported assert { type: 'json' } syntax) and use a named import for @rollup/plugin-babel (its CJS default-export shim doesn't survive ESM interop in modern Node).

Test plan

  • tsc --noEmit in packages/common — refactored code typechecks (pre-existing unrelated errors only)
  • npm run build:sdk succeeds on Node 22.21.1 (verified locally; was failing prior to the rollup fix)
  • Notifications panel renders avatars + track names for follows, reposts, saves, comments
  • Network tab shows a single /v1/notifications request per page (no follow-up /users, /tracks, /playlists round-trips)
  • Pagination via "Load More" still works

Notes

  • related lives at the response root (sibling to data), not per-notification — mirrors the data/related envelope already used by the comments endpoints. Per-page cache-seed instead of per-notification.
  • This PR depends on the API server returning related (already merged in api Add karma to trending #799). The swagger schema catch-up is a separate small PR in the api repo.

🤖 Generated with Claude Code

dylanjeffers and others added 2 commits May 8, 2026 14:42
Instruments three key contest interactions following the existing
'Remix Contest:' event prefix and {remixContestId, trackId} property
shape used by the host/pick-winners events:

  - REMIX_CONTEST_VIEW: contest page/screen first resolves trackId+eventId
  - REMIX_CONTEST_ENTER: user taps Enter Contest / Upload Remix
  - REMIX_CONTEST_VIEW_SUBMISSIONS: user opens the submissions tab

Mobile submissions-tab firing uses useFocusedTab from
react-native-collapsible-tab-view because the contest tabs mount
eagerly (lazy: false) — a plain mount effect would fire even for
users who only view the Details tab.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The /v1/notifications endpoint now returns a `related` block containing
users, tracks, and playlists referenced by the page. Read those directly
to prime the tan-query cache instead of firing separate useUsers /
useTracks / useCollections fetches per page.

- Regenerate NotificationsResponse model with `related?: Related`
- Extend primeRelatedData to handle playlists alongside users/tracks
- Rewrite useNotifications: drop collectEntityIds, drop the three
  prefetch hooks, drop the last-page hold-back logic, drop isAllPending
  and the manual getNotifications type cast
- Switch callers (NotificationPanel, NotificationPage,
  NotificationList) from isAllPending alias to isPending
- Fix rollup.config.ts to read package.json via fs.readFileSync and
  use a named import for @rollup/plugin-babel so the SDK builds on
  Node 22 (per repo .nvmrc)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 11, 2026

⚠️ No Changeset found

Latest commit: 3e2a59e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

…Page

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

🌐 Web preview ready

Preview URL: https://audius-web-preview-pr-14287.audius.workers.dev

Unique preview for this PR (deployed from this branch).
Workflow run

@dylanjeffers dylanjeffers merged commit 202e3e2 into main May 11, 2026
15 checks passed
@dylanjeffers dylanjeffers deleted the claude/zen-ritchie-95cab3 branch May 11, 2026 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant