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) in Rails.cache for 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 fetch block.

References

Screenshots or screen recordings

No UI change.

How to set up and validate locally

  1. 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.

  2. Reload the page. In log/gitaly/current (or the Gitaly request count in log/development_json.log for the graphs#show JSON requests) the second load makes no FindCommits call.

  3. 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'])
  4. 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.

Merge request reports

Loading
Loading