From c623c41c2f917e0773a6e3f0b6c78b027ca846f7 Mon Sep 17 00:00:00 2001 From: Toon Claes Date: Thu, 20 Apr 2017 08:44:01 +0200 Subject: Use a better performing query to find all MRs for pipeline And add some specs. --- app/models/ci/pipeline.rb | 12 +++++------- app/workers/expire_pipeline_cache_worker.rb | 4 ++-- 2 files changed, 7 insertions(+), 9 deletions(-) (limited to 'app') diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index bd5b0ed3cff..b5fe589706f 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -80,22 +80,22 @@ module Ci end after_transition [:created, :pending] => :running do |pipeline| - pipeline.run_after_commit { PipelineMetricsWorker.perform_async(id) } + pipeline.run_after_commit { PipelineMetricsWorker.perform_async(pipeline.id) } end after_transition any => [:success] do |pipeline| - pipeline.run_after_commit { PipelineMetricsWorker.perform_async(id) } + pipeline.run_after_commit { PipelineMetricsWorker.perform_async(pipeline.id) } end after_transition [:created, :pending, :running] => :success do |pipeline| - pipeline.run_after_commit { PipelineSuccessWorker.perform_async(id) } + pipeline.run_after_commit { PipelineSuccessWorker.perform_async(pipeline.id) } end after_transition do |pipeline, transition| next if transition.loopback? pipeline.run_after_commit do - PipelineHooksWorker.perform_async(id) + PipelineHooksWorker.perform_async(pipeline.id) ExpirePipelineCacheWorker.perform_async(pipeline.id) end end @@ -386,9 +386,7 @@ module Ci # All the merge requests for which the current pipeline runs/ran against def all_merge_requests - @all_merge_requests ||= project.merge_requests - .where(source_branch: ref) - .select { |merge_request| merge_request.all_pipelines.includes(self) } + @all_merge_requests ||= project.merge_requests.where(source_branch: ref) end def detailed_status(current_user) diff --git a/app/workers/expire_pipeline_cache_worker.rb b/app/workers/expire_pipeline_cache_worker.rb index 65e7b091506..0210d459048 100644 --- a/app/workers/expire_pipeline_cache_worker.rb +++ b/app/workers/expire_pipeline_cache_worker.rb @@ -2,8 +2,8 @@ class ExpirePipelineCacheWorker include Sidekiq::Worker include PipelineQueue - def perform(id) - pipeline = Ci::Pipeline.find(id) + def perform(pipeline_id) + pipeline = Ci::Pipeline.find(pipeline_id) project = pipeline.project store = Gitlab::EtagCaching::Store.new -- cgit v1.2.1