fix: LRU eviction never removes cached MBTiles (for...in on an array) - #54
fix: LRU eviction never removes cached MBTiles (for...in on an array)#54masaru87 wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughLRUキャッシュ削除処理で削除対象数の計算を調整し、配列のインデックスではなく削除対象のファイル名・キャッシュキーを使ってエントリを削除するよう変更しました。 ChangesLRUキャッシュ削除修正
Estimated code review effort: 1 (Trivial) | ~2 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/lib.ts`:
- Around line 76-81:
MBTILES_LRU_INDEXの上限判定で、現在の件数がMBTILES_CACHE_MAXと等しい場合も新規追加前に1件削除されるよう、idxToDeleteの計算を修正してください。既存の削除処理は維持し、上限を超えないことを確認する回帰テストを追加してください。
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
When MBTILES_LRU_INDEX.length === MBTILES_CACHE_MAX, idxToDelete was 0, so nothing was evicted before the new entry was pushed and the cache grew to MAX+1 (staying one over from then on). Delete length-MAX+1 so the cache holds at MAX after insertion.
|
ご指摘ありがとうございます。off-by-one、その通りでした。
回帰テストについては、 |
The LRU eviction in
getMBTilesInstance(src/lib.ts) never actually removes anything fromMBTILES_CACHE:filenamesToDeleteis an array, sofor...initerates its indices ("0","1", …), not its values.MBTILES_CACHEis keyed bycacheKey(size-mtime-filename), sodelete MBTILES_CACHE["0"]is always a no-op.MBTILES_LRU_INDEXis trimmed bysplice, so the index looks bounded, but the actualMBTILES_CACHE(and theMBTilesSQLite handles it holds) grows without bound pastMBTILES_CACHE_MAX.On a warm Lambda serving several mbtiles files/versions this leaks memory and file descriptors over time. Changed
for...intofor...ofso the eviction deletes the intended cache keys.Summary by CodeRabbit