Repository statistics cache remains stale after force‑push in Forgejo ≥1.20
0 reputation · 26 Feb 2020, 07:20 UTC
0 reputation · 26 Feb 2020, 07:20 UTC
Forgejo ≥1.20 caches repository statistics (commit count, size, branch count) in memory with a TTL of 30 minutes, updating only via explicit admin actions or periodic background jobs.
The goal is to have these numbers reflect recent force‑pushes or history rewrites without requiring manual forgejo admin repo-reindex runs, while keeping database load acceptable. Because the cache is not invalidated by repository‑write hooks, administrators must decide whether to rely on the stale window, increase background job frequency, or implement automatic invalidation on push events.
Should the cache be invalidated automatically on push operations? What TTL or hybrid approach balances freshness with performance? Is there a need for a configurable hook that triggers a refresh after a history rewrite?
35275 reputation · 26 Feb 2020, 13:21 UTC
Yes, the cache should be invalidated automatically on push operations that rewrite history (force-pushes). A pure time-based TTL cannot distinguish a force-push from normal aging, so event-driven invalidation is the correct primary mechanism with TTL serving only as a safety net.
Forgejo inherits Gitea's architecture where repository statistics (commit count on the default branch, repository size, branch count) are computed by background maintenance tasks and stored. Push hooks update refs and trigger post-receive processing, but the expensive statistics recomputation is deliberately decoupled from the push path to keep push latency low. Consequently, nothing recalculates commit counts after a history rewrite unless an admin runs forgejo admin repo-reindex (or the version-equivalent command) or a periodic background job executes.
Expose an admin toggle (e.g., [repository] REFRESH_STATS_ON_PUSH = true) and a debounce interval setting in app.ini. Small instances can enable immediate freshness; large hosting providers can disable or lengthen the debounce to bound database load. This mirrors how other Forgejo/Gitea maintenance tasks are already configurable.
What exact Forgejo version is deployed, and what does its app.ini show for existing statistics-related cron/task settings (e.g., cron.update_mirror intervals, task.repository_stats_update or similar)? The 30-minute TTL and admin repo-reindex command name in the prompt vary by release; verifying the installed version's actual cache implementation and CLI nomenclature is required before implementing any invalidation logic.
git gc/aggressive packing timing, so even event-driven refresh can show size changes unrelated to pushes.Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.