Lfs::FileTranformer caches .gitattributes parser

Prevents `.gitattributes` blob lookup being repeated for every file checked at a given ref
This commit is contained in:
James Edwards-Jones 2018-03-11 19:17:39 +00:00
parent 237a32cc90
commit ca66a04ffe
2 changed files with 8 additions and 3 deletions

View file

@ -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)

View file

@ -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)