summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Edwards-Jones <jedwardsjones@gitlab.com>2018-03-11 19:17:39 +0000
committerJames Edwards-Jones <jedwardsjones@gitlab.com>2018-03-15 21:49:01 +0000
commitca66a04ffec2e311e72b5bdd2c68d3286ef6631c (patch)
tree95d7a0903f3aa3d7ab6cb25792043b3bde9ca6cb
parent237a32cc90d7e2c4b96e3a9ba0fd9e77ff3fc166 (diff)
downloadgitlab-ce-ca66a04ffec2e311e72b5bdd2c68d3286ef6631c.tar.gz
Lfs::FileTranformer caches .gitattributes parser
Prevents `.gitattributes` blob lookup being repeated for every file checked at a given ref
-rw-r--r--app/services/lfs/file_transformer.rb6
-rw-r--r--lib/gitlab/git/repository.rb5
2 files changed, 8 insertions, 3 deletions
diff --git a/app/services/lfs/file_transformer.rb b/app/services/lfs/file_transformer.rb
index 0235d07e529..bdb2f1bea42 100644
--- a/app/services/lfs/file_transformer.rb
+++ b/app/services/lfs/file_transformer.rb
@@ -36,7 +36,11 @@ module Lfs
private
def lfs_file?(file_path)
- repository.attributes_at(branch_name, file_path)['filter'] == 'lfs'
+ cached_attributes.attributes(file_path)['filter'] == 'lfs'
+ end
+
+ def cached_attributes
+ @cached_attributes ||= Gitlab::Git::AttributesAtRefParser.new(repository, branch_name)
end
def create_lfs_object!(lfs_pointer_file, file_content)
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb
index fbc93542619..9811c447a01 100644
--- a/lib/gitlab/git/repository.rb
+++ b/lib/gitlab/git/repository.rb
@@ -1002,8 +1002,9 @@ module Gitlab
# This only checks the root .gitattributes file,
# it does not traverse subfolders to find additional .gitattributes files
#
- # This method is around 30 times slower than `attributes`,
- # which uses `$GIT_DIR/info/attributes`
+ # This method is around 30 times slower than `attributes`, which uses
+ # `$GIT_DIR/info/attributes`. Consider caching AttributesAtRefParser
+ # and reusing that for multiple calls instead of this method.
def attributes_at(ref, file_path)
parser = AttributesAtRefParser.new(self, ref)
parser.attributes(file_path)