Skip to content

perf(meditations): admin list runs ~7 DB queries per row, causing intermittent multi-minute hangs #459

Closed

Description

@Ardnived

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.

  1. Add admin.disableListColumn: true (and disableListFilter: true where applicable) to randomSongUrl, frames, and the tagAssignments group.
  2. Set admin.enableListViewSelectAPI: true on the Meditations collection.
  3. Verify before writing any custom code that this skips the three hooks in the admin list: a disableListColumn field can't be an active column, so enableListViewSelectAPI excludes it from the list select, and Payload skips unselected fields' afterRead hooks (stripUnselectedFields). Confirm via a test / query log that the songs, user-choices, and frames queries no longer fire on a list load.
  4. Verify the durationMinutes column still renders — its afterRead reads the hidden, non-column duration field, which enableListViewSelectAPI may exclude from the select. If it blanks, add duration to 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.ts and tests/int/meditationFrames.int.spec.ts use findByID → stay green.
  • New regression test: an admin/local find (list path) returns rows without firing the songs / user-choices / frames queries.
  • REST find/findByID responses are unchanged (all fields still present, randomSongUrl + enriched frames intact).
  • Manual: Meditations list loads fast; durationMinutes column still shows values; edit view still shows category assignments; GET /api/meditations is unchanged.

Related

Activity

  1. added a commit that references this issue on Jun 5, 2026
    cba9318
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Hold Until

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions