summaryrefslogtreecommitdiff
path: root/app/models/commit.rb
diff options
context:
space:
mode:
authorMatija Čupić <matteeyah@gmail.com>2017-12-21 02:34:35 +0100
committerMatija Čupić <matteeyah@gmail.com>2017-12-21 02:34:35 +0100
commit8c449310e245083e72513ec3addd0d2355333127 (patch)
treea9ca028f0f19cab55e9d3d8afeffd58cc85bf192 /app/models/commit.rb
parent52b4a74a73cbd0b13d46d0bcd9b063e36b520f05 (diff)
parent5d8d72f18e9329978987fcb046467ceacd13c3ab (diff)
downloadgitlab-ce-refactor-cluster-show-page.tar.gz
Merge branch 'master' into refactor-cluster-show-pagerefactor-cluster-show-page
Diffstat (limited to 'app/models/commit.rb')
-rw-r--r--app/models/commit.rb20
1 files changed, 17 insertions, 3 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb
index 13c31111134..2be07ca7d3c 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -86,6 +86,20 @@ class Commit
def valid_hash?(key)
!!(/\A#{COMMIT_SHA_PATTERN}\z/ =~ key)
end
+
+ def lazy(project, oid)
+ BatchLoader.for({ project: project, oid: oid }).batch do |items, loader|
+ items_by_project = items.group_by { |i| i[:project] }
+
+ items_by_project.each do |project, commit_ids|
+ oids = commit_ids.map { |i| i[:oid] }
+
+ project.repository.commits_by(oids: oids).each do |commit|
+ loader.call({ project: commit.project, oid: commit.id }, commit) if commit
+ end
+ end
+ end
+ end
end
attr_accessor :raw
@@ -103,7 +117,7 @@ class Commit
end
def ==(other)
- (self.class === other) && (raw == other.raw)
+ other.is_a?(self.class) && raw == other.raw
end
def self.reference_prefix
@@ -224,8 +238,8 @@ class Commit
notes.includes(:author)
end
- def method_missing(m, *args, &block)
- @raw.__send__(m, *args, &block) # rubocop:disable GitlabSecurity/PublicSend
+ def method_missing(method, *args, &block)
+ @raw.__send__(method, *args, &block) # rubocop:disable GitlabSecurity/PublicSend
end
def respond_to_missing?(method, include_private = false)