Loading
Cache the contributor graph JSON per commit
What does this MR do and why?
- Cache the JSON behind the contributor graph (
/<project>/-/graphs/<ref>.json) inRails.cachefor one hour, keyed by project, the commit the ref resolves to, and whether diff stats were requested. - Today every request walks up to 6000 commits on Gitaly, with diff stats for the chart's default request, and repeat requests for the same ref redo the whole walk. The payload only depends on the resolved commit, so a repeat request within the hour is now served from the cache, and a new commit on the ref changes the key by itself.
- No change to the response body or to the HTML page. Gitaly errors still propagate (and are not cached) because they raise inside the
fetchblock.
References
- Related to https://gitlab.com/gitlab-org/gitlab/-/work_items/636143 (MR 2, the cache)
Screenshots or screen recordings
No UI change.
How to set up and validate locally
-
Open the contributor graph of any project with a repository, for example
http://gdk.test:3000/gitlab-org/gitlab-test/-/graphs/master. The chart loads as before. -
Reload the page. In
log/gitaly/current(or the Gitaly request count inlog/development_json.logfor thegraphs#showJSON requests) the second load makes noFindCommitscall. -
In
bin/rails console, confirm the entries exist:project = Project.find_by_full_path('gitlab-org/gitlab-test') sha = project.repository.commit('master').sha Rails.cache.exist?(['projects', project.id, 'contributor_graph', sha, 'with_stats']) -
Push a commit to
master, reload the graph, and the new commit appears (the key changed, so the walk ran again).
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.