Commit ca66a04f authored by James Edwards-Jones's avatar James Edwards-Jones

Lfs::FileTranformer caches .gitattributes parser

Prevents `.gitattributes` blob lookup being repeated for every file checked at a given ref
parent 237a32cc
...@@ -36,7 +36,11 @@ module Lfs ...@@ -36,7 +36,11 @@ module Lfs
private private
def lfs_file?(file_path) 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 end
def create_lfs_object!(lfs_pointer_file, file_content) def create_lfs_object!(lfs_pointer_file, file_content)
......
...@@ -1002,8 +1002,9 @@ module Gitlab ...@@ -1002,8 +1002,9 @@ module Gitlab
# This only checks the root .gitattributes file, # This only checks the root .gitattributes file,
# it does not traverse subfolders to find additional .gitattributes files # it does not traverse subfolders to find additional .gitattributes files
# #
# This method is around 30 times slower than `attributes`, # This method is around 30 times slower than `attributes`, which uses
# which uses `$GIT_DIR/info/attributes` # `$GIT_DIR/info/attributes`. Consider caching AttributesAtRefParser
# and reusing that for multiple calls instead of this method.
def attributes_at(ref, file_path) def attributes_at(ref, file_path)
parser = AttributesAtRefParser.new(self, ref) parser = AttributesAtRefParser.new(self, ref)
parser.attributes(file_path) parser.attributes(file_path)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment