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

オープン
#19,066 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
リファクタリング
明瞭さ
おおむね明確
活発さ
活発
技術スタック
javascript, node.js

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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().
主要言語
JavaScript
スター
38
フォーク
32
平均マージ
14分
マージ済み PR(30日)
995

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

atomantic/PortOS のほかの issue

atomantic/PortOS の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。