codefloe/forgejo-codefloe
Watch
4
12
Fork
You've already forked forgejo-codefloe
0

fix(git): bound the in-memory last-commit cache #64

Merged
pat-s merged 1 commit from t3code/bound-last-commit-cache into v16.0/forgejo-codefloe 2026-07-28 22:08:13 +00:00
Owner

Addresses the Unbounded In-Memory Cache item (Caching, P0) of #19.

LastCommitCache keeps a level-2 map[string]*Commit (commitCache) that was only ever inserted into, never bounded. A long-lived Repository walking large trees could grow it without limit, pinning every distinct commit it ever resolved for the repository's lifetime.

Fix

Cap commitCache at 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 (Cache interface) cache, so an eviction costs at most a re-fetch of one commit on its next lookup.

Fork-safe

modules/git/last_commit_cache.go is 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

  • TestLastCommitCacheBoundsCommitCache inserts 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 vet on modules/git, gofmt/gofumpt clean.

Closes the Caching-P0 checkbox in #19.

Addresses the **Unbounded In-Memory Cache** item (Caching, P0) of #19. `LastCommitCache` keeps a level-2 `map[string]*Commit` (`commitCache`) that was only ever inserted into, never bounded. A long-lived `Repository` walking large trees could grow it without limit, pinning every distinct commit it ever resolved for the repository's lifetime. ## Fix Cap `commitCache` at 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 (`Cache` interface) cache, so an eviction costs at most a re-fetch of one commit on its next lookup. ## Fork-safe `modules/git/last_commit_cache.go` is 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 - `TestLastCommitCacheBoundsCommitCache` inserts 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 vet` on `modules/git`, gofmt/gofumpt clean. Closes the Caching-P0 checkbox in #19.
pat-s force-pushed t3code/bound-last-commit-cache from 498ea75cad
Some checks failed
testing / backend-checks (pull_request) Has been cancelled
testing / frontend-checks (pull_request) Has been cancelled
testing / test-unit (pull_request) Has been cancelled
testing / test-e2e (pull_request) Has been cancelled
testing / test-remote-cacher (redis) (pull_request) Has been cancelled
testing / test-remote-cacher (valkey) (pull_request) Has been cancelled
testing / test-remote-cacher (garnet) (pull_request) Has been cancelled
testing / test-mysql (pull_request) Has been cancelled
testing / test-pgsql (pull_request) Has been cancelled
testing / test-sqlite (pull_request) Has been cancelled
to 65683bd05f
Some checks failed
testing / backend-checks (pull_request) Failing after 5m16s
testing / frontend-checks (pull_request) Successful in 1m16s
testing / test-unit (pull_request) Has been cancelled
testing / test-e2e (pull_request) Has been cancelled
testing / test-remote-cacher (redis) (pull_request) Has been cancelled
testing / test-remote-cacher (valkey) (pull_request) Has been cancelled
testing / test-remote-cacher (garnet) (pull_request) Has been cancelled
testing / test-mysql (pull_request) Has been cancelled
testing / test-pgsql (pull_request) Has been cancelled
testing / test-sqlite (pull_request) Has been cancelled
2026-07-28 14:48:45 +00:00
Compare
pat-s scheduled this pull request to auto merge when all checks succeed 2026-07-28 14:50:24 +00:00
pat-s force-pushed t3code/bound-last-commit-cache from 65683bd05f
Some checks failed
testing / backend-checks (pull_request) Failing after 5m16s
testing / frontend-checks (pull_request) Successful in 1m16s
testing / test-unit (pull_request) Has been cancelled
testing / test-e2e (pull_request) Has been cancelled
testing / test-remote-cacher (redis) (pull_request) Has been cancelled
testing / test-remote-cacher (valkey) (pull_request) Has been cancelled
testing / test-remote-cacher (garnet) (pull_request) Has been cancelled
testing / test-mysql (pull_request) Has been cancelled
testing / test-pgsql (pull_request) Has been cancelled
testing / test-sqlite (pull_request) Has been cancelled
to 1be71e256d
Some checks failed
testing / backend-checks (pull_request) Successful in 11m6s
testing / frontend-checks (pull_request) Successful in 1m13s
testing / test-unit (pull_request) Has been cancelled
testing / test-e2e (pull_request) Has been cancelled
testing / test-remote-cacher (redis) (pull_request) Has been cancelled
testing / test-remote-cacher (valkey) (pull_request) Has been cancelled
testing / test-remote-cacher (garnet) (pull_request) Has been cancelled
testing / test-mysql (pull_request) Has been cancelled
testing / test-pgsql (pull_request) Has been cancelled
testing / test-sqlite (pull_request) Has been cancelled
2026-07-28 15:15:25 +00:00
Compare
pat-s force-pushed t3code/bound-last-commit-cache from 1be71e256d
Some checks failed
testing / backend-checks (pull_request) Successful in 11m6s
testing / frontend-checks (pull_request) Successful in 1m13s
testing / test-unit (pull_request) Has been cancelled
testing / test-e2e (pull_request) Has been cancelled
testing / test-remote-cacher (redis) (pull_request) Has been cancelled
testing / test-remote-cacher (valkey) (pull_request) Has been cancelled
testing / test-remote-cacher (garnet) (pull_request) Has been cancelled
testing / test-mysql (pull_request) Has been cancelled
testing / test-pgsql (pull_request) Has been cancelled
testing / test-sqlite (pull_request) Has been cancelled
to 8d12c764bb
Some checks failed
testing / test-unit (pull_request) Failing after 7m44s
testing / frontend-checks (pull_request) Successful in 1m19s
testing / backend-checks (pull_request) Successful in 9m37s
testing / test-mysql (pull_request) Successful in 31m41s
testing / test-e2e (pull_request) Successful in 22m50s
testing / test-remote-cacher (redis) (pull_request) Has been skipped
testing / test-remote-cacher (valkey) (pull_request) Has been skipped
testing / test-pgsql (pull_request) Successful in 53m51s
testing / test-remote-cacher (garnet) (pull_request) Has been skipped
testing / test-sqlite (pull_request) Successful in 51m47s
2026-07-28 17:13:00 +00:00
Compare
pat-s force-pushed t3code/bound-last-commit-cache from 8d12c764bb
Some checks failed
testing / test-unit (pull_request) Failing after 7m44s
testing / frontend-checks (pull_request) Successful in 1m19s
testing / backend-checks (pull_request) Successful in 9m37s
testing / test-mysql (pull_request) Successful in 31m41s
testing / test-e2e (pull_request) Successful in 22m50s
testing / test-remote-cacher (redis) (pull_request) Has been skipped
testing / test-remote-cacher (valkey) (pull_request) Has been skipped
testing / test-pgsql (pull_request) Successful in 53m51s
testing / test-remote-cacher (garnet) (pull_request) Has been skipped
testing / test-sqlite (pull_request) Successful in 51m47s
to 3789a79158
All checks were successful
testing / frontend-checks (pull_request) Successful in 1m12s
testing / test-mysql (pull_request) Successful in 31m11s
testing / test-remote-cacher (valkey) (pull_request) Successful in 1m16s
testing / test-remote-cacher (garnet) (pull_request) Successful in 1m14s
testing / backend-checks (pull_request) Successful in 7m17s
testing / test-unit (pull_request) Successful in 8m43s
testing / test-e2e (pull_request) Successful in 25m37s
testing / test-remote-cacher (redis) (pull_request) Successful in 1m15s
testing / test-pgsql (pull_request) Successful in 47m51s
testing / test-sqlite (pull_request) Successful in 43m57s
issue-labels / backporting (pull_request_target) Has been skipped
milestone / set (pull_request_target) Has been skipped
2026-07-28 20:51:08 +00:00
Compare
pat-s merged commit 86088e46df into v16.0/forgejo-codefloe 2026-07-28 22:08:13 +00:00
pat-s deleted branch t3code/bound-last-commit-cache 2026-07-28 22:08:13 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
codefloe/forgejo-codefloe!64
No description provided.