refactor: electron/main/ipc/ogp.ts cache を LruCache に置換し TTL sweep を撤去#352
Merged
Conversation
- `Map<string, CacheEntry>` + 手動 1-pass TTL sweep + oldest 探索 (22 行) を `src/lib/lru-cache.ts` の `LruCache<string, CacheEntry>(MAX_CACHE_SIZE=500)` に 置換。cap eviction は LruCache が O(1) で担う - 24h TTL sweep は撤去。freshness は cacheGet の read-time TTL check で substitute (invisible な stale は cap-based LRU で bounded) - main-side から `src/lib/lru-cache.ts` を import できるよう `tsconfig.node.json` の include に追加。renderer bundle と main bundle の 両方に含まれるが、lru-cache.ts は self-contained なので追加コストなし - 定数名 `MAX_CACHE_ENTRIES` → `MAX_CACHE_SIZE` で sibling cache (mermaid.ts / slide-render.ts / math.ts / link-cards.ts) と命名整合 - cacheGet は LruCache.get() を継続使用 (touch)。main-side ogp cache は set が 1 回、get が多数の pattern なので .peek() 化すると FIFO 相当に退化する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
electron main process 側の OGP メタデータキャッシュ (
electron/main/ipc/ogp.ts) を、renderer 側で PR #349–#351 で導入・展開したsrc/lib/lru-cache.tsのLruCacheに統合。LruCache 5 caller 目 で、renderer / main の両 bundle 境界を跨いで cache 実装を統一する。関連 Issue
なし (HANDOFF 98/99/100 で defer 継続していた次段タスク)
移行 Stage
(main-side OGP IPC の内部リファクタで、Stage 5 に相当するが仕様変更なし)
変更内容
electron/main/ipc/ogp.tsMap<string, CacheEntry>+ 手動 1-pass TTL sweep + oldest 探索 (22 行) をLruCache<string, CacheEntry>(MAX_CACHE_SIZE=500)に置換cacheGetの read-time TTL check で substitute (invisible な stale は cap-based LRU で bounded)MAX_CACHE_ENTRIES→MAX_CACHE_SIZEで sibling cache (mermaid / slide-render / math / link-cards) と命名整合cacheGetはLruCache.get()を継続使用 (touch)。main-side ogp cache は set が 1 回・get が多数の pattern で、.peek()化すると FIFO 相当に退化するためtsconfig.node.jsonsrc/lib/lru-cache.tsを import 可能にするため include に追加。self-contained なので追加コストなしelectron/main/ipc/ogp.test.ts動作確認
pnpm tsc -p tsconfig.node.jsonPASSpnpm tsc -p tsconfig.web.jsonPASSpnpm biome checkPASSpnpm vitest run2547 pass (0 fail, 2 skipped) — うちelectron/main/ipc/ogp.test.ts12/12 passpnpm electron-vite buildPASS検証エビデンス
リスク分類
tier: medium — reasons なし (classify-risk.sh の default 分類)
実行した検証
pnpm tsc -p tsconfig.node.jsonpnpm tsc -p tsconfig.web.jsonpnpm biome check electron/main/ipc/ogp.ts electron/main/ipc/ogp.test.ts tsconfig.node.jsonpnpm vitest runpnpm electron-vite buildレビュー指摘と対応
/code-review medium 詳細:
ogp.ts:29-30cache コメントが「最古 1 件」→ LRU 意味論明示 (644f7c1) → CONFIRMED+FIXEDcacheGetexpired 分岐で.get()→.peek()化 → REFUTED (happy path が 3→4 map ops で悪化する net loss)cacheSetinline → REFUTED (testnow注入で helper が必要)追跡先
なし
Draft 判定