Skip to content

docs(swagger): add user_id query to three cache-priming endpoints#839

Merged
raymondjacobson merged 1 commit into
mainfrom
api/personalization-for-cache-prime-endpoints
May 20, 2026
Merged

docs(swagger): add user_id query to three cache-priming endpoints#839
raymondjacobson merged 1 commit into
mainfrom
api/personalization-for-cache-prime-endpoints

Conversation

@raymondjacobson
Copy link
Copy Markdown
Member

Summary

Adds an optional user_id query parameter to three routes that embed user objects in their response and rely on app.getMyId(c) to personalize them. Today the SDK request types don't expose this field, so clients never send ?user_id= and the backend computes personalization against MyID = 0 — i.e. does_current_user_follow and friends return false for every embedded user.

Why

Audit follow-up to #837 / #838 (notifications). Same bug class:

  1. Endpoint embeds users in related.users (or a collection's user field).
  2. Backend handler passes MyID: app.getMyId(c) into dbv1.ParallelParams to personalize those users.
  3. getMyId(c) reads from the query string ?user_id=. With no query value, MyID = 0 and the SQL short-circuits does_current_user_follow to false.
  4. Web/mobile prime those un-personalized users into a shared tan-query cache (via primeRelatedData for remix-contests, primeCollectionDataprimeUserData for new-releases). The cache write only happens when the slot is empty, so once poisoned the entry sticks until the user navigates to that profile and a personalized fetch overwrites it.

Affected client hooks:

Spec-only change

resolveMyIdMiddleware already reads c.Query(\"user_id\") globally (resolve_middleware.go:24-28), so the Go handlers personalize correctly as soon as the SDK starts sending the param. No backend code change required, no Go test updates required.

No path-placeholder collision this time — all three routes are either query-only (new-releases, remix-contests) or already use id as the path placeholder (users/{id}/contests). The generator will emit a clean userId?: string field.

Test plan

  • Spec validates in CI.
  • After SDK regen + apps update (follow-up PR): on a fresh app load with a signed-in account that follows artists surfaced on the Browse → New Albums and Explore → Contests pages, confirm Following state renders correctly without first having to visit each artist's profile.
  • Network inspector on the three endpoints shows ?user_id=<hashed-current-user-id> and does_current_user_follow: true for users actually followed in related.users.

🤖 Generated with Claude Code

GET /events/remix-contests, GET /users/{id}/contests, and
GET /playlists/new-releases all embed user objects (track owners /
contest hosts / album creators) in their responses, and their handlers
already call app.getMyId(c) to feed MyID into the Parallel query that
hydrates related users (does_current_user_follow etc). But their SDK
request types didn't expose a user_id query field, so the wire request
never carried the requester id and the backend computed personalization
against MyID=0 — every embedded user came back with
does_current_user_follow: false.

Clients prime those embedded users into a shared user cache
(primeRelatedData / primeCollectionData → primeUserData), and the cache
write only happens when the slot is empty, so the bad state sticks
until a personalized fetch overwrites it. Same shape as the bug fixed
for /notifications in #837 / #838.

Spec-only change. resolveMyIdMiddleware already reads ?user_id= from
the query, so the Go handlers personalize correctly as soon as clients
start sending the param.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@raymondjacobson raymondjacobson merged commit 9fd7e23 into main May 20, 2026
5 checks passed
@raymondjacobson raymondjacobson deleted the api/personalization-for-cache-prime-endpoints branch May 20, 2026 22:25
raymondjacobson added a commit to AudiusProject/apps that referenced this pull request May 20, 2026
Audit follow-up to the notifications fix. Three more hooks were priming
un-personalized users into the shared tan-query user cache because their
SDK request types didn't expose the personalization query param:

- useAllRemixContests   → events.getRemixContests
- useUserRemixContests  → users.getContestsByUser
- useNewAlbumReleases   → playlists.getPlaylistsNewReleases

Each handler already calls app.getMyId(c) on the backend; the param just
wasn't being sent. AudiusProject/api#839 added the user_id query field
to all three routes. This PR:

- Regenerates @audius/sdk so each request type accepts userId?: string
  (additive, no breaking change).
- Updates the three hooks to pass userId: Id.parse(currentUserId).

After this the cache primes carry the right does_current_user_follow
state out of the gate, so explore/contests/new-releases surfaces don't
need a profile visit to correct the follow indicators.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
raymondjacobson added a commit to AudiusProject/apps that referenced this pull request May 20, 2026
…14367)

## Summary

Three more hooks were priming un-personalized users into the shared user
cache — same bug class as the notifications fix in
[#14366](#14366). API spec
change merged in
[AudiusProject/api#839](AudiusProject/api#839);
this PR consumes it.

| Hook | SDK call | Prime |
| --- | --- | --- |
| `useAllRemixContests` | `events.getRemixContests` | `primeRelatedData`
|
| `useUserRemixContests` | `users.getContestsByUser` |
`primeRelatedData` |
| `useNewAlbumReleases` | `playlists.getPlaylistsNewReleases` |
`primeCollectionData` → `primeUserData` |

In every case the backend handler already calls `app.getMyId(c)` to feed
`MyID` into the `Parallel` query that hydrates embedded users — the
query param just wasn't being sent because the SDK request type didn't
expose it. With no value, `MyID = 0` and the SQL
[short-circuited](https://github.com/AudiusProject/api/blob/main/api/dbv1/get_users.sql.go#L129-L136)
`does_current_user_follow` to false for every embedded user. Clients
then primed those into a shared cache that other surfaces read.

## Changes

| File | Change |
| --- | --- |
| `packages/sdk/src/sdk/api/generated/default/apis/EventsApi.ts` | Add
`userId?: string` to `GetRemixContestsRequest`; map to
`queryParameters['user_id']`. |
| `packages/sdk/src/sdk/api/generated/default/apis/UsersApi.ts` | Add
`userId?: string` to `GetContestsByUserRequest`; map to
`queryParameters['user_id']`. Path field is still `id` (the contest
host); query `userId` is the requester. |
| `packages/sdk/src/sdk/api/generated/default/apis/PlaylistsApi.ts` |
Add `userId?: string` to `GetPlaylistsNewReleasesRequest`; map to
`queryParameters['user_id']`. |
| `packages/common/src/api/tan-query/events/useAllRemixContests.ts` |
Pull `currentUserId` via `useCurrentUserId`; pass as `userId`. |
| `packages/common/src/api/tan-query/events/useUserRemixContests.ts` |
Same. Note this hook already took a `userId` prop for the contest host —
that maps to the path `id`. `currentUserId` is separately threaded as
the query. |
| `packages/common/src/api/tan-query/collection/useNewAlbumReleases.ts`
| Pull `currentUserId`; pass as `userId`. |
| `.changeset/personalization-three-endpoints.md` | Minor `@audius/sdk`
bump for the new optional fields. |

## Note on the SDK files in this diff

I edited the generated `*.ts` files by hand here because `npm install`
in my environment was blocked by a date-pinned registry constraint,
which broke `node_modules` and stopped both `gen.js` and the rollup
build from running. The edits are deterministic — they replicate the
exact pattern openapi-generator already produces for analogous endpoints
(e.g. `GetTrendingPlaylistsRequest` in the same `PlaylistsApi.ts`). A
fresh `npm run gen` on a clean checkout should produce the same diff.
Worth a quick visual confirmation during review.

## Test plan

- [ ] CI green (typecheck/lint/tests).
- [ ] On a fresh app load with a signed-in account: explore → contests
carousel, an artist's contests tab, and browse → new albums all show
correct Following state for surfaced artists without first having to
navigate to each profile.
- [ ] Network inspector on each of the three endpoints carries
`?user_id=<hashed-current-user-id>` and `does_current_user_follow: true`
for users actually followed in `related.users` / collection owners.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant