Cache Review archive reads and scope triageQueueItem to the target item's producer(s)

Abierto
#19,066 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Refactorización
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
javascript, node.js

Línea de trabajo

Start in server/services/review.js at loadArchive() (around lines 162-164), comparing it with the itemsCache pattern in loadItems() (lines 132-152), then check getItems() for the new Date() calls in the sort comparator. Next, read triageQueueItem() in server/services/reviewQueue.js (around lines 1378-1387) and its gatherFullQueue() call. Done means archive reads are cached and coalesced, archive writes invalidate the cache, triage gathers only the producers for the item's source prefix, and the 503, 404 and 400 responses are unchanged, with tests in server/services/review.test.js and server/services/reviewQueue.test.js.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

effort:low model:light performance performance-efficiency plan planner:gemini-4-neon source:performance-efficiency

Audit slice: server/services/review.js, server/services/reviewQueue.js (re-verification of 2026-11-24 performance-efficiency slice) — Date: 2026-11-26
Scope: small

Batched model:light + effort:low performance-efficiency findings in the Review Hub services:

  • Cache archive.json by mtimeMs/size with in-flight coalescing in server/services/review.js

    • Problem: loadItems() (server/services/review.js:132-152) caches items.json by { mtimeMs, size }, but loadArchive() (server/services/review.js:162-164) has no cache or in-flight deduplication. Even after #18598 paged the HTTP responses, every GET /api/review/items page navigation re-reads and JSON.parse()s the entire multi-MB archive.json from disk, and every GET /api/review/queue?view=history triggers two concurrent reads + parses of archive.json in parallel (from the todo producer at server/services/reviewQueue.js:562 and the history producer at server/services/reviewQueue.js:591). Additionally, getItems() (review.js:276-280) allocates two new Date(...) objects per comparator call while sorting all live + archived items before slicing.
    • Impact: Repeated multi-MB disk reads and main-thread JSON.parse() stalls on every Review History open and page turn, doubled on view=history.
    • Fix: Add an mtimeMs + size cache (archiveCache) and in-flight read coalescing to loadArchive() in server/services/review.js (mirroring itemsCache), invalidate it on every ARCHIVE_FILE write (applyRetention, loadItemCollection's save wrapper, reopenItem, removeMemoryApprovalItems), clone only the returned items in getItems() (after filter/sort/paginate; mutation paths still clone before mutating), and use Date.parse (or pre-parsed timestamps) instead of new Date(...) inside the sort() comparator.
  • Scope triageQueueItem() to the target item's owning producer(s) in server/services/reviewQueue.js

    • Problem: In server/services/reviewQueue.js:1378-1387, triageQueueItem() calls gatherFullQueue({}, { applyTriageState: false, now }) to validate a single item before snoozing, unsnoozing, or dismissing it. That runs getActiveGoalOptions() and fans out across all 15 live producers (Brain, Threads with per-task/per-app lookups, Ask, CoS approvals, CoS feedback, Message drafts, Review items, Todos, Notifications, GitHub notifications DB query, Stacker News, X, Product engagement, System health alerts, Software updates, Backup state), immediately before POST /api/review/queue/triage (server/routes/review.js:110) emits queue:changed and triggers connected clients to rebuild the full queue a second time.
    • Impact: Every single snooze, unsnooze, or dismiss click pays a full 15-source cross-domain fan-out (DB queries, filesystem reads, and potential system-health sweep) twice in a row.
    • Fix: Map the parsed source prefix of queueItemId in server/services/reviewQueue.js to the minimal producer set that can emit it (PRODUCERS_BY_SOURCE[source] for direct sources; ['review', 'notifications'] for adapted sources memory, goal-fidelity, plan, content, autopilot; ['cos', 'review', 'notifications'] for cos), pass an onlySources option to gatherFullQueue(), and skip getActiveGoalOptions() unless 'ask' is included. Preserve the exact 503 SOURCE_UNAVAILABLE, 404 NOT_FOUND, and 400 CAPABILITY_UNAVAILABLE responses.

Acceptance Criteria

  • loadArchive() in server/services/review.js caches parsed archive data by { mtimeMs, size }, coalesces concurrent reads so GET /api/review/queue?view=history parses archive.json at most once, and invalidates the cache on every write to ARCHIVE_FILE.
  • getItems() does not allocate new Date() objects inside the sort() comparator and clones only returned items (preserving cache immutability for callers).
  • triageQueueItem() in server/services/reviewQueue.js gathers only the producer(s) capable of emitting the target queueItemId's source prefix and skips getActiveGoalOptions() when 'ask' is not among them.
  • Unit tests in server/services/review.test.js and server/services/reviewQueue.test.js verify archive cache hits/invalidation/coalescing and scoped producer gathering in triageQueueItem().
Lenguaje dominante
JavaScript
Estrellas
38
Forks
32
Merge medio
14 min
PR fusionados (30 d)
995

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de atomantic/PortOS

Todos los issues de atomantic/PortOS

Issues similares

Más issues de JavaScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.