summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOswaldo Ferreira <oswaldo@gitlab.com>2018-06-08 17:47:44 -0300
committerOswaldo Ferreira <oswaldo@gitlab.com>2018-06-08 17:49:34 -0300
commitad96d64158f8a2ea98ec8f850379831791b57ded (patch)
tree42c6f372c33e98cac701b6318d4dabe1a12d4c37
parent8d82db5b739c510919bfb3f89cb7b142156ba6c5 (diff)
downloadgitlab-ce-ad96d64158f8a2ea98ec8f850379831791b57ded.tar.gz
Lazy load uncached blobs in order to first-load using gitaly batch method correctly
-rw-r--r--app/models/blobs_service.rb15
-rw-r--r--lib/gitlab/diff/file.rb3
2 files changed, 14 insertions, 4 deletions
diff --git a/app/models/blobs_service.rb b/app/models/blobs_service.rb
index 5e4adc3a95d..a7c3b3e7bfa 100644
--- a/app/models/blobs_service.rb
+++ b/app/models/blobs_service.rb
@@ -11,6 +11,13 @@ class BlobsService
@path = path
end
+ def lazy_load_uncached_blob
+ return unless content_sha
+ return if cache_exists?
+
+ uncached_blob
+ end
+
# We need blobs data (content) in order to highlight diffs (see
# Gitlab::Diff:Highlight), and we don't cache this (Blob#data) on Redis,
# mainly because it's a quite heavy information to cache for every blob.
@@ -21,7 +28,7 @@ class BlobsService
return unless content_sha
return uncached_blob unless highlighted
- cache_exists? ? cached_blob : uncached_blob
+ cache_exists? ? cached_blob : uncached_blob&.itself
end
@@ -39,7 +46,7 @@ class BlobsService
private
- attr_reader :content_sha
+ attr_reader :content_sha, :project, :path
def cacheable_blob_hash
CACHED_METHODS.each_with_object({}) do |_method, hash|
@@ -52,7 +59,7 @@ class BlobsService
end
def uncached_blob
- @uncached_blob ||= Blob.lazy(@project, @content_sha, @path)&.itself
+ Blob.lazy(project, content_sha, path)
end
def cache
@@ -68,6 +75,6 @@ class BlobsService
end
def cache_key
- [@project.id, @content_sha, @path]
+ [project.id, content_sha, path]
end
end
diff --git a/lib/gitlab/diff/file.rb b/lib/gitlab/diff/file.rb
index 95e2df007fd..105f67de839 100644
--- a/lib/gitlab/diff/file.rb
+++ b/lib/gitlab/diff/file.rb
@@ -25,6 +25,9 @@ module Gitlab
@repository = repository
@diff_refs = diff_refs
@fallback_diff_refs = fallback_diff_refs
+
+ old_blob_service.lazy_load_uncached_blob
+ new_blob_service.lazy_load_uncached_blob
end
def position(position_marker, position_type: :text)