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

Aperta
#19,066 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Refactoring
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
javascript, node.js

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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().
Lingua principale
JavaScript
Stelle
38
Fork
32
Merge medio
14m
PR unite (30g)
995

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di atomantic/PortOS

Tutte le issue di atomantic/PortOS

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.