fix(git): bound the in-memory last-commit cache #64
No reviewers
Labels
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
codefloe/forgejo-codefloe!64
Loading…
Reference in a new issue
No description provided.
Delete branch "t3code/bound-last-commit-cache"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Addresses the Unbounded In-Memory Cache item (Caching, P0) of #19.
LastCommitCachekeeps a level-2map[string]*Commit(commitCache) that was only ever inserted into, never bounded. A long-livedRepositorywalking large trees could grow it without limit, pinning every distinct commit it ever resolved for the repository's lifetime.Fix
Cap
commitCacheat a fixed size (maxCommitCacheSize, 5000) and evict an existing entry once the cap is reached before inserting a new one. The map is purely an optimization on top of the level-1 (Cacheinterface) cache, so an eviction costs at most a re-fetch of one commit on its next lookup.Fork-safe
modules/git/last_commit_cache.gois a cold file (3 commits in ~18 months, all chore/branding/linter, last real logic change in 2023), and the change is confined to a new helper plus one call site, so it should merge cleanly across future upstream updates.Verification
TestLastCommitCacheBoundsCommitCacheinserts well past the cap and asserts the map never exceeds it, and that re-inserting an existing key neither grows nor evicts.go build/go vetonmodules/git, gofmt/gofumpt clean.Closes the Caching-P0 checkbox in #19.
498ea75cad65683bd05f65683bd05f1be71e256d1be71e256d8d12c764bb8d12c764bb3789a79158