Repository navigation
feat(lectures): include per-lecture userChoices in the /for-audience feed - #727
Merged
Merged
Conversation
…feed
WeMeditateWeb's content-index block SSR-loads the lecture feed once, since
the SahajCloud API key is server-only, then filters client-side. It cannot
render UserChoice filter pills, because the feed carries no per-lecture
membership. `contentIndexCard` already reads `doc.userChoices` and degrades
to a plain grid without it.
`LecturePlayerData` gains `userChoices: { id, title }[]`. `title` is
localized on `user-choices`, and neither endpoint's `find` passes a locale
of its own, so it resolves against the request's locale.
Three things worth naming:
- `userChoices` moves onto `LECTURE_FEED_SELECT` rather than the
related-lectures ranking spread, since both endpoints return it now. The
ranking loop reads the same documents and only compares `id`.
- `LECTURE_FEED_POPULATE` bounds a populated row to its title. `user-choices`
is an upload collection with a virtual URL field and several localized
fields — unbounded, selecting the relationship pulls all of them for every
lecture in the candidate pool, which is the N+1 shape #541 closed one level
up.
- A clip reports its own memberships, never its parent's. A clip is assigned
independently, so inheriting would report a membership no editor set.
Every new assertion was confirmed failing first, at the site that causes it:
| Defect reintroduced | Goes red |
| --- | --- |
| `userChoices` dropped from `LECTURE_FEED_SELECT` | `selects userChoices…` |
| `LECTURE_FEED_POPULATE` widened past `title` | `bounds a populated user-choice…` |
| `shapeUserChoices` filters out unpopulated ids | 2 helper cases |
| `shapeLecture` never calls `shapeUserChoices` | 2 wiring cases |
| a clip reads `metadataSource.userChoices` | the clip case |
| the endpoint's find pins `locale: 'en'` | `resolves the title for the request locale` |
The fourth row is why the wiring cases exist. Unwiring the helper left all
1608 unit tests green — a pure helper's spec cannot see whether its caller
calls it.
Fixture pre-mortem: the unit fixture assumes a full lecture's `type` is
`'full'` (the only value `shapeLecture` branches on is `'clip'`) and that it
owns its own `metadata`. Checked against
`src/collections/Lectures/Lectures.ts` and `src/lib/lectures/lectureShape.ts`.
Closes #526
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YPw1LL76jc2JT8K47fkHzN
… emits `customEndpoints.ts` already said to keep this schema in lockstep with `LecturePlayerData` in `src/lib/lectures/lectureShape.ts`. Only a comment said so, so adding a field to one and forgetting the other drifted silently. `additionalProperties: false` does not catch it either — nothing validates a response against this schema at runtime. Three cases pin the property set, `userChoices` being required, and a user-choice row's own two fields. Confirmed failing first: dropping `userChoices` from the schema's `required` list turns the second red. The property list is the same one `lectures-for-audience.int.spec.ts` and `meditation-lectures.int.spec.ts` pin against a real response, so the two ends now have to move together. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01YPw1LL76jc2JT8K47fkHzN
…es them `cacheHeaders.ts` promises a custom endpoint's response "never outlives its freshest input". The previous commit broke that promise: both lecture feeds now embed a user choice's localized `title`, but `user-choices` was not a `CacheableSlug`, so the responses could not tag it and its writes fired no purge hook. Renaming a user choice left stale labels at the edge for the full 300s/600s TTL. `user-choices` joins `CACHE_TTLS` at the 600s default — display metadata, renamed rarely — and all three responses tag it. The derived TTL does not move, since `resolveTtl` takes the lowest and `audiences` is still 300s. Adding the slug also makes the built-in `GET /api/user-choices` read cacheable, which is the same published-only public metadata by the same rule. Confirmed failing first: dropping the tag from `forAudience.ts` turns the new `tags the response with user-choices` case red. Two smaller fixes from the same review: - `tests/int/lectures-for-audience.int.spec.ts`'s #541 N+1 regression case passed `select: LECTURE_FEED_SELECT` with no `populate`. With `userChoices` now in that select, it was hydrating user-choices unbounded and no longer reproducing what the endpoints do. - The `LECTURE_FEED_POPULATE` comment said "~8 localized fields". There are five. It now names what is actually stripped, and records that `id` survives the bound — which is what the ranking loop depends on. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01YPw1LL76jc2JT8K47fkHzN
…bounds - `docs/rules/endpoints.md` listed only `defaultPopulate` as the way to narrow a relationship's fields. A read's own `populate` is the other, and it is what this change uses — the bound belongs to the lecture feeds, not to every reader of `user-choices`. - `DEPLOYMENT.md` enumerates the live Cloudflare Cache Rule's slug list, which is now narrower than `CACHE_TTLS`. Says why, so nobody "fixes" the mismatch by caching a read nobody asked to cache. - `docs/architecture.md` and `tests/COVERAGE.md` name the new field and what covers it. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01YPw1LL76jc2JT8K47fkHzN
|
🚅 Deployed to the SahajCloud-pr-727 environment in sahajcloud
1 service not affected by this PR
|
railway-app
Bot
temporarily deployed
to
sahajcloud / SahajCloud-pr-727
September 7, 2026 17:32
Destroyed
An adversarial review pass found the bound had no behavioural coverage: deleting `populate: LECTURE_FEED_POPULATE` from all three reads left the whole suite green. The two specs that named it asserted the constant's own value, which fails only when someone edits the constant — and then the fix is to edit the expectation. Both change-detectors are gone. In their place, one integration case reads with the real select and populate and asserts a populated user choice keeps `id` and `title` while `lectures`, `children`, `url` and `filename` are all absent. Confirmed failing first: dropping the populate argument from every call site turns exactly that case red, and nothing else. `related-lectures` gained the same gap in reverse — it pinned the response key set and never the value, on the endpoint that also reads `userChoices` for ranking. One case now asserts a real id and title there. Three smaller items from the same review: - **The `LECTURE_FEED_POPULATE` comment was wrong about the cost.** It called the unbounded read "the same N+1 shape" as #541. It is not: population goes through `payloadDataLoader`, which batches the whole pool into one `find`, so the waste scales with distinct user choices, not with pool size. The comment now says what the bound is really worth — `user-choices`' two `join` fields, one of them at `defaultLimit: 100` — and warns that profiling it as an N+1 will find nothing. A wrong story invites the next reader to conclude the bound is decorative and delete it. - `shapeUserChoices` guards a non-object entry. Payload cannot produce one, but the function is exported and its doc block invites other callers; `{ id: undefined }` would serialize to a row missing the `id` the OpenAPI schema marks required. - `as const` → `satisfies PopulateType`, matching `LECTURE_FEED_SELECT` two lines above, so the guarantee is local to the declaration. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01YPw1LL76jc2JT8K47fkHzN
railway-app
Bot
temporarily deployed
to
sahajcloud / SahajCloud-pr-727
September 7, 2026 17:36
Destroyed
sydevs-bot
marked this pull request as ready for review
September 7, 2026 17:48
Ardnived
requested changes
Sep 7, 2026
…ted type Review asked for three things on #727. All three applied. `LectureUserChoice` is gone. The row type now derives from the generated `UserChoice`, per the rule `src/types/AGENTS.md` already carries and #659 enforced: delete the hand-written alias, use the generated interface. `Pick<UserChoice, 'id' | 'title'>` alone would have loosened it. `UserChoice` declares `title?: string | null`, so `Pick` makes the key optional, while the OpenAPI schema for these rows marks `title` required. `Required<Pick<…>>` keeps the key mandatory and its value nullable, which is what both the endpoint and the schema already promise. `shapeUserChoices` keeps its job but loses most of its bulk. The comment restated what `LECTURE_FEED_POPULATE` already does, and the function's own `flatMap` existed for a guard against a non-object row — unreachable, since `Lecture['userChoices']` types every element as `number | UserChoice` and both callers are TypeScript. It is a `map` over the two shapes Payload can return, with the depth-0 id case kept: an unpopulated id becomes `{ id, title: null }` rather than being dropped, because dropping it reports the lecture as belonging to no user-choice at all. Confirmed still covered: replacing that branch with `[]` turns `keeps an unpopulated id…` and `preserves the order…` red. The `user-choices` entry in `CACHE_TTLS` loses its three-line comment. The reasoning lives in the PR body and on the ticket. Gate green: lint, typecheck, typecheck:tests, 1613 unit tests. Targeted integration: 80 across `lectures-for-audience` and `meditation-lectures`. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_011WhkKoQTCGvJymk1XySE9r
railway-app
Bot
temporarily deployed
to
sahajcloud / SahajCloud-pr-727
September 7, 2026 18:36
Destroyed
Contributor
Author
|
All three review comments applied.
On the built-in: it is Gate green: lint, typecheck, typecheck:tests, 1613 unit tests. Integration: 80 across two int specs. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Ardnived
approved these changes
Sep 7, 2026
sydevs-bot
pushed a commit
that referenced
this pull request
Sep 7, 2026
Brings #727 (per-lecture userChoices in the /for-audience feed) onto this branch after its squash-merge, so the next review round reads current code. One conflict, in `src/lib/lectures/lectureShape.ts`: both sides rewrote the `@/payload-types` import. This branch adds `LectureMetadata` (the generated interface it exists to adopt); main adds `UserChoice` and the `FeedUserChoice` alias. Both are kept — the two changes are additive and independent. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01XmzSzbuPBtmPwBnsFuaoPk
sydevs-bot
pushed a commit
that referenced
this pull request
Sep 7, 2026
Brings #727 onto this branch after its squash-merge. The one conflict was `src/payload-types.ts`, the generated file this PR exists to stabilize. Resolved by regenerating with `pnpm generate:types` rather than by hand — which reproduced this branch's version byte for byte, the property the PR adds. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01XmzSzbuPBtmPwBnsFuaoPk
Ardnived
pushed a commit
that referenced
this pull request
Nov 5, 2026
…ted type Review asked for three things on #727. All three applied. `LectureUserChoice` is gone. The row type now derives from the generated `UserChoice`, per the rule `src/types/AGENTS.md` already carries and #659 enforced: delete the hand-written alias, use the generated interface. `Pick<UserChoice, 'id' | 'title'>` alone would have loosened it. `UserChoice` declares `title?: string | null`, so `Pick` makes the key optional, while the OpenAPI schema for these rows marks `title` required. `Required<Pick<…>>` keeps the key mandatory and its value nullable, which is what both the endpoint and the schema already promise. `shapeUserChoices` keeps its job but loses most of its bulk. The comment restated what `LECTURE_FEED_POPULATE` already does, and the function's own `flatMap` existed for a guard against a non-object row — unreachable, since `Lecture['userChoices']` types every element as `number | UserChoice` and both callers are TypeScript. It is a `map` over the two shapes Payload can return, with the depth-0 id case kept: an unpopulated id becomes `{ id, title: null }` rather than being dropped, because dropping it reports the lecture as belonging to no user-choice at all. Confirmed still covered: replacing that branch with `[]` turns `keeps an unpopulated id…` and `preserves the order…` red. The `user-choices` entry in `CACHE_TTLS` loses its three-line comment. The reasoning lives in the PR body and on the ticket. Gate green: lint, typecheck, typecheck:tests, 1613 unit tests. Targeted integration: 80 across `lectures-for-audience` and `meditation-lectures`. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_011WhkKoQTCGvJymk1XySE9r
Ardnived
pushed a commit
that referenced
this pull request
Nov 5, 2026
Brings #727 (per-lecture userChoices in the /for-audience feed) onto this branch after its squash-merge, so the next review round reads current code. One conflict, in `src/lib/lectures/lectureShape.ts`: both sides rewrote the `@/payload-types` import. This branch adds `LectureMetadata` (the generated interface it exists to adopt); main adds `UserChoice` and the `FeedUserChoice` alias. Both are kept — the two changes are additive and independent. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01XmzSzbuPBtmPwBnsFuaoPk
This branch was successfully deployed
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
/api/lectures/for-audienceand/api/meditations/{id}/related-lecturesnow return each lecture'suserChoicesas{ id, title }, with the title localized to the request locale.contentIndexCardalready readsdoc.userChoicesand degrades to a plain grid without it, so the filter pills light up with no change on that side.user-choicesbecomes a cacheable, purgeable slug. Both feeds embed its titles, so a rename now invalidates them instead of leaving stale labels at the edge.Changes
src/lib/lectures/lectureShape.ts—userChoicesonLecturePlayerData, theshapeUserChoicesprojection, andLECTURE_FEED_POPULATEsrc/collections/{Lectures/endpoints/forAudience,Meditations/endpoints/lectures}.ts— pass the populate bound, taguser-choicessrc/plugins/cache/policy.ts—user-choicesjoinsCACHE_TTLSat the 600s defaultsrc/plugins/openapi/customEndpoints.ts— theLecturePlayerDataschema, now pinned by a specPreview
Contract impact
Additive on a shape two repos consume.
LecturePlayerDatais hand-written here, not generated, so nothing needs regenerating downstream.lib/cms-blocks.ts:462-473already mapsdoc.userChoicesinto facets, keeping only populated rows with a non-empty string title. Every row this emits is populated, so the pills appear on the next deploy. Related: feat(content-index): client-side filtering + MusicLibrary songs WeMeditateWeb#55.Migration
None. No field config changed —
jsonSchema, columns and relationships are untouched.Test results
pnpm lint,pnpm typecheck,pnpm typecheck:tests,pnpm test:unit(125 files, 1613 tests)lectures-for-audience(49),meditation-lectures(32),lectures(31) on the first round; ✓ 80 across the first two re-run on0601358.Every new assertion was confirmed failing first, at the site that causes it:
userChoicesdropped fromLECTURE_FEED_SELECTexpectedKeyspinspopulate: LECTURE_FEED_POPULATEdropped from all three readsstrips everything but title…shapeUserChoicesdrops an unpopulated idkeeps an unpopulated id…,preserves the order…shapeLecturenever callsshapeUserChoicesmetadataSource.userChoiceslocale: 'en'resolves the title for the request localeuserChoicesdropped from the OpenAPIrequiredlistmarks userChoices required…user-choicescache tag droppedtags the response with user-choices…Two of those rows exist because the first version of this PR did not have them, and an adversarial pass found both:
shapeUserChoicesfromshapeLectureleft all 1608 unit tests green. A pure helper's spec cannot see whether its caller calls it.populatebound from every call site also left everything green. The specs that named it asserted the constant's own literal value, which only fails when someone edits the constant. Both change-detectors are gone, replaced by one case that reads with the real bound and asserts the stripped fields are absent.Manual verification
curl -H "Authorization: clients API-Key <key>" "$URL/api/lectures/for-audience?audiences=<id>&limit=20"— that lecture carriesuserChoices: [{ id, title }], and a lecture with none carries[].&locale=fron a user choice that has a French title — the title changes, the id does not.CLOUDFLARE_ZONE_ID+CLOUDFLARE_CACHE_PURGE_TOKENset, otherwise TTL is the invalidation path.Notes for reviewer
user-choicesjoiningCACHE_TTLSis the judgement call here. It was the smallest fix that keepscacheHeaders.ts's "never outlives its freshest input" promise — a slug outside that map is not aCacheableSlug, so the feeds could not tag it at all. Two intended side effects, both beyond these endpoints:GET /api/user-choicesbecomes cacheable, and everyuser-choiceswrite now fires a Cloudflare tag purge (CACHEABLE_SLUGSdrives the purge hooks).DEPLOYMENT.mdrecords that the live Cloudflare Cache Rule need not list the slug, and that leaving it out just keeps that one readDYNAMIC. This paragraph replaces the inline comment review asked to delete.Required<Pick<UserChoice, 'id' | 'title'>>, not the barePickreview suggested.UserChoicedeclarestitle?, soPickalone makes the key optional while the OpenAPI schema marks it required. Aliased once asFeedUserChoicerather than inlined at both sites.metadataandfullLectureId, which a clip does inherit. A clip is assigned to a user choice independently, so inheriting would report a membership no editor set. Say if you want the opposite.{ id, title: null }rather than being dropped. Both callers read atdepth: 2so it should not arise, but dropping the row would report the lecture as belonging to no user choice — indistinguishable from the truth.src/collections/*/endpoints/) and returned no finding. It confirmed bothwemeditate-*client roles can already read/api/user-choicesdirectly, so{id, title}is not new information to them.Detail
Review round
0601358. All three comments applied.LectureUserChoicedeleted in favour of the generated interface, per the rulesrc/types/AGENTS.mdcarries and #659 enforced.shapeUserChoiceskeeps its behaviour and loses the bulk — comment from 11 lines to 6, and theflatMapguard dropped as unreachable, sinceLecture['userChoices']types every element and both callers are TypeScript. TheCACHE_TTLScomment removed.The function itself stays, and the reason is worth recording: the built-in review was reaching for is
populate, which this PR already uses —LECTURE_FEED_POPULATEnarrows a populated row to{ id, title }at the read, so nothing is picked in the helper. What remains is collapsing the two shapes ahasManyreturns, ids at depth 0 and documents at depth ≥ 1, for which Payload has no helper.Why
populateand notdefaultPopulate.docs/rules/endpoints.mdnamed onlydefaultPopulatefor narrowing a relationship's fields. That would narrowuser-choicesfor every reader, including the admin. The bound belongs to these two feeds, so it goes on the read.idsurvives it —buildFindManyArgshard-setscolumns = { id: true }whenever a select is present — which is what lets the related-lectures ranking loop keep comparinguc.id.What the bound is actually worth, since the first version got this wrong. It is not the #541 N+1, and profiling it as one finds nothing: population goes through
payloadDataLoader, which batches the whole pool into a singlefind, so the waste scales with the number of distinct user choices rather than with pool size. What it prevents is a wide row —user-choices' twojoinfields (children, andlecturesatdefaultLimit: 100), the upload columns, the virtual URL field, and four localized relationships. The comment on the constant now says this, because the wrong story invites the next reader to conclude the bound is decorative and delete it.CANDIDATE_SELECTlost a line.related-lecturesspreaduserChoices: trueexplicitly; it now inherits it fromLECTURE_FEED_SELECT, since the feed shape returns it. The ranking loop reads the same documents.One thing the bound does not cover. A clip's nested
fullLectureparent hydrates its ownuserChoicesa level down, whichshapeLecturediscards. That is a second batched round trip, not a per-row one, and narrowing it would needLectures.defaultPopulate— a global change for a local saving. Recorded in the comment rather than fixed.A pre-existing gap the security review surfaced, filed nowhere yet.
requireActiveClientgates on "publishedclientsuser" and not on project.sahaj-atlas-clientcannot read/api/user-choicesdirectly, yet can call/for-audience— which already hands it the whole lecture feed. This change widens that by two public display fields rather than opening it. Say if you want a ticket.Unrelated churn kept out. A test run regenerated
src/payload-types.tswithSUPPORTED_TIMEZONESreordered. That is #722, now fixed in #728 —@vvo/tzdbsorts by current UTC offset, and Chile entered DST on 2026-09-06, one day after the committed snapshot was written.Closes #526
🤖 Written by the sydevs autonomous loop — see what this is
🤖 Generated with Claude Code
https://claude.ai/code/session_01YPw1LL76jc2JT8K47fkHzN