Speed up used languages calculation on charts page
We removed calls from our code to Rugged::Repository#fetch_attributes:
<340e111e04
>
However, we didn't remove calls from within Linguist. This method is only called
when calculating the languages for a repository on the Charts page:
<https://github.com/github/linguist/blob/v4.7.0/lib/linguist/lazy_blob.rb#L33-L36>
We can safely use our own Gitlab::Git::Attributes here. On staging, for the
GitLab CE repo, this makes the calculation take about a third of the time:
# Before
Benchmark.realtime do
Linguist::Repository.new(repository.rugged,
repository.rugged.head.target_id).languages
end
#=> 23.67193900188431
# After
Benchmark.realtime do
Linguist::Repository.new(repository.rugged,
repository.rugged.head.target_id).languages
end
#=> 8.945212290156633
This commit is contained in:
parent
587a73b2dd
commit
fe0898cc14
2 changed files with 29 additions and 0 deletions
4
changelogs/unreleased/speed-up-graphs.yml
Normal file
4
changelogs/unreleased/speed-up-graphs.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
title: Speed up used languages calculation on charts page
|
||||
merge_request:
|
||||
author:
|
25
config/initializers/rugged_use_gitlab_git_attributes.rb
Normal file
25
config/initializers/rugged_use_gitlab_git_attributes.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
# We don't want to ever call Rugged::Repository#fetch_attributes, because it has
|
||||
# a lot of I/O overhead:
|
||||
# <https://gitlab.com/gitlab-org/gitlab_git/commit/340e111e040ae847b614d35b4d3173ec48329015>
|
||||
#
|
||||
# While we don't do this from within the GitLab source itself, the Linguist gem
|
||||
# has a dependency on Rugged and uses the gitattributes file when calculating
|
||||
# repository-wide language statistics:
|
||||
# <https://github.com/github/linguist/blob/v4.7.0/lib/linguist/lazy_blob.rb#L33-L36>
|
||||
#
|
||||
# The options passed by Linguist are those assumed by Gitlab::Git::Attributes
|
||||
# anyway, and there is no great efficiency gain from just fetching the listed
|
||||
# attributes with our implementation, so we ignore the additional arguments.
|
||||
#
|
||||
module Rugged
|
||||
class Repository
|
||||
module UseGitlabGitAttributes
|
||||
def fetch_attributes(name, *)
|
||||
@attributes ||= Gitlab::Git::Attributes.new(path)
|
||||
@attributes.attributes(name)
|
||||
end
|
||||
end
|
||||
|
||||
prepend UseGitlabGitAttributes
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue