diff options
| author | Alejandro RodrÃguez <alejorro70@gmail.com> | 2018-02-28 19:22:44 -0300 |
|---|---|---|
| committer | Alejandro RodrÃguez <alejorro70@gmail.com> | 2018-03-05 11:14:43 -0300 |
| commit | 0a4ee10eda01e23ddea0e6b4f80f61df3ffaabde (patch) | |
| tree | e80e5f0c65498576459a814fcb5da8ef7da6faa3 /lib | |
| parent | 369d34c7c8e006d2568e4a1b12b6493830811270 (diff) | |
| download | gitlab-ce-0a4ee10eda01e23ddea0e6b4f80f61df3ffaabde.tar.gz | |
Fix n+1 issue by not reloading fully loaded blobs
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/gitlab/git/blob.rb | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/gitlab/git/blob.rb b/lib/gitlab/git/blob.rb index b2fca2c16de..eabcf46cf58 100644 --- a/lib/gitlab/git/blob.rb +++ b/lib/gitlab/git/blob.rb @@ -238,9 +238,9 @@ module Gitlab self.__send__("#{key}=", options[key.to_sym]) # rubocop:disable GitlabSecurity/PublicSend end - @loaded_all_data = false # Retain the actual size before it is encoded @loaded_size = @data.bytesize if @data + @loaded_all_data = @loaded_size == size end def binary? @@ -255,10 +255,15 @@ module Gitlab # memory as a Ruby string. def load_all_data!(repository) return if @data == '' # don't mess with submodule blobs - return @data if @loaded_all_data - Gitlab::GitalyClient.migrate(:git_blob_load_all_data) do |is_enabled| - @data = begin + # Even if we return early, recalculate wether this blob is binary in + # case a blob was initialized as text but the full data isn't + @binary = nil + + return if @loaded_all_data + + @data = Gitlab::GitalyClient.migrate(:git_blob_load_all_data) do |is_enabled| + begin if is_enabled repository.gitaly_blob_client.get_blob(oid: id, limit: -1).data else @@ -269,7 +274,6 @@ module Gitlab @loaded_all_data = true @loaded_size = @data.bytesize - @binary = nil end def name |
