Repository navigation
Description
Summary
Opening the Meditations list in the admin panel is intermittently unusable. A CMS user reports it sometimes loads fine, but sometimes hangs for 10+ minutes — even after reopening the admin in a fresh tab — then works again later. It makes their work very slow.
Root cause
The admin list issues a find (findMany: true) with no field-level select, so every field afterRead hook runs on every row, regardless of admin.hidden / admin.condition (display-only) or defaultPopulate (relationship-hydration-only). Per meditation row:
| Field | Cost per row | Shown in list? |
|---|---|---|
randomSongUrl (src/collections/Meditations/hooks/randomSongUrl.ts) |
2 queries (count + offset find on songs) |
No — admin.hidden |
tagAssignments.{asMorning,asAfternoon,asEvening,asNight}Meditation (src/collections/Meditations/Meditations.ts:38, the virtualJoinField factory) |
4 queries to user-choices |
No — edit-only condition |
frames enrichment (src/collections/Meditations/Meditations.ts:382) |
1 query to frames |
No |
≈ 7 D1 round-trips per row, none feeding a displayed column (defaultColumns is label, thumbnail, _status, type, durationMinutes). At the default page size that's ~70 serial round-trips inside a single Cloudflare Worker request. On a D1 cold start or load spike this exceeds the Worker CPU/time budget (cpu_ms = 300000 in wrangler.toml) and the request errors/times out; the user retries until a warm path succeeds — exactly the reported "temperamental" behaviour.
These fields aren't shown in the list and aren't needed there: randomSongUrl and frames are consumed by the public API and the edit view; tagAssignments is only used in the admin edit view. The fix is to stop computing them for the admin list only — the public REST API stays unchanged for every field.
Proposed fix — native flags first, guard only as fallback
Step 1 (primary, test-first): native list-select exclusion.
- Add
admin.disableListColumn: true(anddisableListFilter: truewhere applicable) torandomSongUrl,frames, and thetagAssignmentsgroup. - Set
admin.enableListViewSelectAPI: trueon the Meditations collection. - Verify before writing any custom code that this skips the three hooks in the admin list: a
disableListColumnfield can't be an active column, soenableListViewSelectAPIexcludes it from the listselect, and Payload skips unselected fields'afterReadhooks (stripUnselectedFields). Confirm via a test / query log that the songs, user-choices, and frames queries no longer fire on a list load. - Verify the
durationMinutescolumn still renders — itsafterReadreads the hidden, non-columndurationfield, whichenableListViewSelectAPImay exclude from theselect. If it blanks, adddurationto the selected set (or keep that field selectable).
Admin-only — the public REST API responses are unchanged for all fields.
Step 2 (fallback only — skip if Step 1 works).
If the spike shows the native flags do not skip the hooks in the admin list, add an early-return to each of the three hooks for the admin-list path only: if (req.payloadAPI === 'local' && findMany === true) return … (null for randomSongUrl; [] for the tagAssignments join fields; normalized-but-unenriched frames — frames.map(v => ({ ...v, timestamp: Math.round(v.timestamp) })) — for frames). This leaves REST (payloadAPI === 'REST') and the admin edit view (findByID, findMany undefined) untouched. Signals verified: findMany === true only on find (payload/dist/collections/operations/find.js); req.payloadAPI ∈ 'local' | 'REST' | 'GraphQL' (payload/dist/types/index.d.ts).
Validation
- Existing
tests/int/meditations.int.spec.tsandtests/int/meditationFrames.int.spec.tsusefindByID→ stay green. - New regression test: an admin/local
find(list path) returns rows without firing the songs / user-choices / frames queries. - REST
find/findByIDresponses are unchanged (all fields still present,randomSongUrl+ enrichedframesintact). - Manual: Meditations list loads fast;
durationMinutescolumn still shows values; edit view still shows category assignments;GET /api/meditationsis unchanged.
Related
- Replace virtual join fields with native PayloadCMS join fields #249 — replace the
virtualJoinFieldworkaround with native join fields once the upstream Payload bug is fixed. Keep that refactor consistent with the changes here.
Metadata
Metadata
Assignees
Labels
Type
Fields
Hold Until
Activity
perf(meditations): skip per-row afterRead hooks in admin list (#463)
refactor(meditations): remove randomSongUrl virtual field (#474)