summaryrefslogtreecommitdiff
path: root/app/models/blob.rb
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2018-02-28 20:36:55 +0100
committerKamil Trzciński <ayufan@ayufan.eu>2018-02-28 20:36:55 +0100
commit965dc28691e2d70b7040e28d90ccbc3721a9e416 (patch)
tree84258f35b72f2e7ce6a7198db66032df4ad5aadb /app/models/blob.rb
parente3fafa7632e038927085cf8c8228c93be44b36bd (diff)
parent7fabc892f251740dbd9a4755baede662e6854870 (diff)
downloadgitlab-ce-965dc28691e2d70b7040e28d90ccbc3721a9e416.tar.gz
Merge commit '7fabc892f251740dbd9a4755baede662e6854870' into object-storage-ee-to-ce-backport
Diffstat (limited to 'app/models/blob.rb')
-rw-r--r--app/models/blob.rb17
1 files changed, 16 insertions, 1 deletions
diff --git a/app/models/blob.rb b/app/models/blob.rb
index ad0bc2e2ead..29e762724e3 100644
--- a/app/models/blob.rb
+++ b/app/models/blob.rb
@@ -76,12 +76,24 @@ class Blob < SimpleDelegator
new(blob, project)
end
+ def self.lazy(project, commit_id, path)
+ BatchLoader.for(commit_id: commit_id, path: path).batch do |items, loader|
+ project.repository.blobs_at(items.map(&:values)).each do |blob|
+ loader.call({ commit_id: blob.commit_id, path: blob.path }, blob) if blob
+ end
+ end
+ end
+
def initialize(blob, project = nil)
@project = project
super(blob)
end
+ def inspect
+ "#<#{self.class.name} oid:#{id[0..8]} commit:#{commit_id[0..8]} path:#{path}>"
+ end
+
# Returns the data of the blob.
#
# If the blob is a text based blob the content is converted to UTF-8 and any
@@ -95,7 +107,10 @@ class Blob < SimpleDelegator
end
def load_all_data!
- super(project.repository) if project
+ # Endpoint needed: gitlab-org/gitaly#756
+ Gitlab::GitalyClient.allow_n_plus_1_calls do
+ super(project.repository) if project
+ end
end
def no_highlighting?