diff options
author | Toon Claes <toon@gitlab.com> | 2017-04-18 21:26:56 +0200 |
---|---|---|
committer | Toon Claes <toon@gitlab.com> | 2017-04-24 10:07:01 +0200 |
commit | ccb9beeed0e418ef4dea201b3507bd2f4a14b4a2 (patch) | |
tree | ff75331541746d5ab9e27d9151cbccdae214fb43 /app | |
parent | f07edb5af1e18be817e49e0afd86f59a6eef1cd9 (diff) | |
download | gitlab-ce-ccb9beeed0e418ef4dea201b3507bd2f4a14b4a2.tar.gz |
Properly expire cache for **all** MRs of a pipeline
Turn ExpirePipelineCacheService into Worker so it can fetch all the
merge requests for which the pipeline runs or did run against.
Diffstat (limited to 'app')
-rw-r--r-- | app/models/ci/pipeline.rb | 10 | ||||
-rw-r--r-- | app/services/ci/expire_pipeline_cache_service.rb | 51 | ||||
-rw-r--r-- | app/workers/expire_pipeline_cache_worker.rb | 51 |
3 files changed, 59 insertions, 53 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 445247f1b41..bd5b0ed3cff 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -96,8 +96,7 @@ module Ci pipeline.run_after_commit do PipelineHooksWorker.perform_async(id) - Ci::ExpirePipelineCacheService.new(project, nil) - .execute(pipeline) + ExpirePipelineCacheWorker.perform_async(pipeline.id) end end @@ -385,6 +384,13 @@ module Ci .select { |merge_request| merge_request.head_pipeline.try(:id) == self.id } end + # 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) } + end + def detailed_status(current_user) Gitlab::Ci::Status::Pipeline::Factory .new(self, current_user) diff --git a/app/services/ci/expire_pipeline_cache_service.rb b/app/services/ci/expire_pipeline_cache_service.rb deleted file mode 100644 index 91d9c1d2ba1..00000000000 --- a/app/services/ci/expire_pipeline_cache_service.rb +++ /dev/null @@ -1,51 +0,0 @@ -module Ci - class ExpirePipelineCacheService < BaseService - attr_reader :pipeline - - def execute(pipeline) - @pipeline = pipeline - store = Gitlab::EtagCaching::Store.new - - store.touch(project_pipelines_path) - store.touch(commit_pipelines_path) if pipeline.commit - store.touch(new_merge_request_pipelines_path) - merge_requests_pipelines_paths.each { |path| store.touch(path) } - - Gitlab::Cache::Ci::ProjectPipelineStatus.update_for_pipeline(@pipeline) - end - - private - - def project_pipelines_path - Gitlab::Routing.url_helpers.namespace_project_pipelines_path( - project.namespace, - project, - format: :json) - end - - def commit_pipelines_path - Gitlab::Routing.url_helpers.pipelines_namespace_project_commit_path( - project.namespace, - project, - pipeline.commit.id, - format: :json) - end - - def new_merge_request_pipelines_path - Gitlab::Routing.url_helpers.new_namespace_project_merge_request_path( - project.namespace, - project, - format: :json) - end - - def merge_requests_pipelines_paths - pipeline.merge_requests.collect do |merge_request| - Gitlab::Routing.url_helpers.pipelines_namespace_project_merge_request_path( - project.namespace, - project, - merge_request, - format: :json) - end - end - end -end diff --git a/app/workers/expire_pipeline_cache_worker.rb b/app/workers/expire_pipeline_cache_worker.rb new file mode 100644 index 00000000000..65e7b091506 --- /dev/null +++ b/app/workers/expire_pipeline_cache_worker.rb @@ -0,0 +1,51 @@ +class ExpirePipelineCacheWorker + include Sidekiq::Worker + include PipelineQueue + + def perform(id) + pipeline = Ci::Pipeline.find(id) + project = pipeline.project + store = Gitlab::EtagCaching::Store.new + + store.touch(project_pipelines_path(project)) + store.touch(commit_pipelines_path(project, pipeline.commit)) if pipeline.commit + store.touch(new_merge_request_pipelines_path(project)) + merge_requests_pipelines_paths(project, pipeline).each { |path| store.touch(path) } + + Gitlab::Cache::Ci::ProjectPipelineStatus.update_for_pipeline(pipeline) + end + + private + + def project_pipelines_path(project) + Gitlab::Routing.url_helpers.namespace_project_pipelines_path( + project.namespace, + project, + format: :json) + end + + def commit_pipelines_path(project, commit) + Gitlab::Routing.url_helpers.pipelines_namespace_project_commit_path( + project.namespace, + project, + commit.id, + format: :json) + end + + def new_merge_request_pipelines_path(project) + Gitlab::Routing.url_helpers.new_namespace_project_merge_request_path( + project.namespace, + project, + format: :json) + end + + def merge_requests_pipelines_paths(project, pipeline) + pipeline.all_merge_requests.collect do |merge_request| + Gitlab::Routing.url_helpers.pipelines_namespace_project_merge_request_path( + project.namespace, + project, + merge_request, + format: :json) + end + end +end |