From ca66a04ffec2e311e72b5bdd2c68d3286ef6631c Mon Sep 17 00:00:00 2001 From: James Edwards-Jones Date: Sun, 11 Mar 2018 19:17:39 +0000 Subject: Lfs::FileTranformer caches .gitattributes parser Prevents `.gitattributes` blob lookup being repeated for every file checked at a given ref --- app/services/lfs/file_transformer.rb | 6 +++++- lib/gitlab/git/repository.rb | 5 +++-- 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) -- cgit v1.2.1