Cache last commit id for path
What does this MR do?
To speed up the Repository#last_commit_for_path, caching the last commit id for path.
Benchmark
Script
require "benchmark/ips"
Benchmark.ips do |x|
x.config(time: 5, warmup: 2)
project = Project.find_with_namespace("gitlab-org/gitlab-ce")
repository = project.repository
commit = repository.commit("master")
x.report("cache_last_commit_id_for_path") do
repository.cache_last_commit_id_for_path(commit.id, nil)
end
x.report("last_commit_id_for_path") do
repository.last_commit_id_for_path(commit.id, nil)
end
x.compare!
end
Result
cache_last_commit_id_for_path
2.449k (±16.8%) i/s - 12.105k
last_commit_id_for_path
110.703 (± 5.4%) i/s - 561.000
Comparison:
cache_last_commit_id_for_path: 2449.2 i/s
last_commit_id_for_path: 110.7 i/s - 22.12x slower
Are there points in the code the reviewer needs to double check?
- Including the commit id in cache key, so it is not necessary to clear the cache manually.
- Cache data increase by this MR.
Why was this MR needed?
Showing repository files is very slow.
The Repository#last_commit_for_path is called by the number of contents in RefsController#logs_tree.
Does this MR meet the acceptance criteria?
-
Changelog entry added -
Documentation created/updated -
API support added - Tests
-
Added for this feature/bug -
All builds are passing
-
-
Conform by the merge request performance guides -
Conform by the style guides -
Branch has no merge conflicts with master
(if it does - rebase it please) -
Squashed related commits together