summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabio Pitino <fpitino@gitlab.com>2019-06-26 11:07:39 +0100
committerFabio Pitino <fpitino@gitlab.com>2019-06-26 11:08:58 +0100
commitb8c5e970353712fce08aa6f394e39fadea644108 (patch)
treeb8ea0c1dea406c7a82c6c7546252ca9686a312c4
parent2428a550e401ae3083d9dbe604a6a362703e4779 (diff)
downloadgitlab-ce-fix-multiple-gitaly-calls-in-pipelines-controller.tar.gz
Try use BatchLoader to solve N+1 Gitaly callsfix-multiple-gitaly-calls-in-pipelines-controller
This is only a WIP
-rw-r--r--app/models/ci/pipeline.rb4
-rw-r--r--app/models/project.rb8
2 files changed, 12 insertions, 0 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index 3727a9861aa..64ab98ff29e 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -480,6 +480,10 @@ module Ci
project.commit(git_ref) == commit
end
+ def project_commit(git_ref)
+ @project_lazy_commit ||= project.lazy_commit(git_ref)
+ end
+
def retried
@retried ||= (statuses.order(id: :desc) - statuses.latest)
end
diff --git a/app/models/project.rb b/app/models/project.rb
index 351d08eaf63..8f69f405808 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -731,6 +731,14 @@ class Project < ApplicationRecord
repository.commit(ref)
end
+ def lazy_commit(ref = 'HEAD')
+ BatchLoader.for(ref).batch do |refs, loader|
+ repository.commits_by(oids: refs).each_with_index do |commit, i|
+ loader.call(refs[i], commit) if commit
+ end
+ end
+ end
+
def commit_by(oid:)
repository.commit_by(oid: oid)
end