summaryrefslogtreecommitdiff
path: root/app/services/ci
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2019-04-15 16:31:45 +0000
committerLin Jen-Shin <godfat@godfat.org>2019-04-15 16:31:45 +0000
commite5301b658336f387d82ff039ff9214e347c900a8 (patch)
treea4f26b00a7d63004441501757fb400e6fa90f37b /app/services/ci
parent57cdf56aa7df41b013d9c47c6b12bf5a9e20e4f4 (diff)
parent16259796539f19f7b04ad078a28aa38c5b50912f (diff)
downloadgitlab-ce-e5301b658336f387d82ff039ff9214e347c900a8.tar.gz
Merge branch 'sh-fix-pipeline-delete-caching' into 'master'
Properly expire all pipeline caches when pipeline is deleted Closes #60469 See merge request gitlab-org/gitlab-ce!27334
Diffstat (limited to 'app/services/ci')
-rw-r--r--app/services/ci/destroy_pipeline_service.rb4
-rw-r--r--app/services/ci/expire_pipeline_cache_service.rb62
2 files changed, 64 insertions, 2 deletions
diff --git a/app/services/ci/destroy_pipeline_service.rb b/app/services/ci/destroy_pipeline_service.rb
index 2292ec42b16..9aea20c45f7 100644
--- a/app/services/ci/destroy_pipeline_service.rb
+++ b/app/services/ci/destroy_pipeline_service.rb
@@ -5,9 +5,9 @@ module Ci
def execute(pipeline)
raise Gitlab::Access::AccessDeniedError unless can?(current_user, :destroy_pipeline, pipeline)
- pipeline.destroy!
+ Ci::ExpirePipelineCacheService.new.execute(pipeline, delete: true)
- Gitlab::Cache::Ci::ProjectPipelineStatus.new(pipeline.project).delete_from_cache
+ pipeline.destroy!
end
end
end
diff --git a/app/services/ci/expire_pipeline_cache_service.rb b/app/services/ci/expire_pipeline_cache_service.rb
new file mode 100644
index 00000000000..d8d38128af6
--- /dev/null
+++ b/app/services/ci/expire_pipeline_cache_service.rb
@@ -0,0 +1,62 @@
+# frozen_string_literal: true
+
+module Ci
+ class ExpirePipelineCacheService
+ def execute(pipeline, delete: false)
+ store = Gitlab::EtagCaching::Store.new
+
+ update_etag_cache(pipeline, store)
+
+ if delete
+ Gitlab::Cache::Ci::ProjectPipelineStatus.new(pipeline.project).delete_from_cache
+ else
+ Gitlab::Cache::Ci::ProjectPipelineStatus.update_for_pipeline(pipeline)
+ end
+ end
+
+ private
+
+ def project_pipelines_path(project)
+ Gitlab::Routing.url_helpers.project_pipelines_path(project, format: :json)
+ end
+
+ def project_pipeline_path(project, pipeline)
+ Gitlab::Routing.url_helpers.project_pipeline_path(project, pipeline, format: :json)
+ end
+
+ def commit_pipelines_path(project, commit)
+ Gitlab::Routing.url_helpers.pipelines_project_commit_path(project, commit.id, format: :json)
+ end
+
+ def new_merge_request_pipelines_path(project)
+ Gitlab::Routing.url_helpers.project_new_merge_request_path(project, format: :json)
+ end
+
+ def each_pipelines_merge_request_path(pipeline)
+ pipeline.all_merge_requests.each do |merge_request|
+ path = Gitlab::Routing.url_helpers.pipelines_project_merge_request_path(merge_request.target_project, merge_request, format: :json)
+
+ yield(path)
+ end
+ end
+
+ # Updates ETag caches of a pipeline.
+ #
+ # This logic resides in a separate method so that EE can more easily extend
+ # it.
+ #
+ # @param [Ci::Pipeline] pipeline
+ # @param [Gitlab::EtagCaching::Store] store
+ def update_etag_cache(pipeline, store)
+ project = pipeline.project
+
+ store.touch(project_pipelines_path(project))
+ store.touch(project_pipeline_path(project, pipeline))
+ store.touch(commit_pipelines_path(project, pipeline.commit)) unless pipeline.commit.nil?
+ store.touch(new_merge_request_pipelines_path(project))
+ each_pipelines_merge_request_path(pipeline) do |path|
+ store.touch(path)
+ end
+ end
+ end
+end