2019-07-31 22:56:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Ci
|
|
|
|
class ExpirePipelineCacheService
|
2021-04-17 20:07:23 +05:30
|
|
|
class UrlHelpers
|
|
|
|
include ::Gitlab::Routing
|
|
|
|
include ::GitlabRoutingHelper
|
|
|
|
end
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
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)
|
2021-04-17 20:07:23 +05:30
|
|
|
url_helpers.project_pipelines_path(project, format: :json)
|
2019-07-31 22:56:46 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def project_pipeline_path(project, pipeline)
|
2021-04-17 20:07:23 +05:30
|
|
|
url_helpers.project_pipeline_path(project, pipeline, format: :json)
|
2019-07-31 22:56:46 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def commit_pipelines_path(project, commit)
|
2021-04-17 20:07:23 +05:30
|
|
|
url_helpers.pipelines_project_commit_path(project, commit.id, format: :json)
|
2019-07-31 22:56:46 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def new_merge_request_pipelines_path(project)
|
2021-04-17 20:07:23 +05:30
|
|
|
url_helpers.project_new_merge_request_path(project, format: :json)
|
2019-07-31 22:56:46 +05:30
|
|
|
end
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
def pipelines_project_merge_request_path(merge_request)
|
2021-04-17 20:07:23 +05:30
|
|
|
url_helpers.pipelines_project_merge_request_path(merge_request.target_project, merge_request, format: :json)
|
2021-01-03 14:25:43 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def merge_request_widget_path(merge_request)
|
2021-04-17 20:07:23 +05:30
|
|
|
url_helpers.cached_widget_project_json_merge_request_path(merge_request.project, merge_request, format: :json)
|
2021-01-03 14:25:43 +05:30
|
|
|
end
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
def each_pipelines_merge_request_path(pipeline)
|
|
|
|
pipeline.all_merge_requests.each do |merge_request|
|
2021-01-03 14:25:43 +05:30
|
|
|
yield(pipelines_project_merge_request_path(merge_request))
|
|
|
|
yield(merge_request_widget_path(merge_request))
|
2019-07-31 22:56:46 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
def graphql_pipeline_path(pipeline)
|
|
|
|
url_helpers.graphql_etag_pipeline_path(pipeline)
|
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
def graphql_pipeline_sha_path(sha)
|
|
|
|
url_helpers.graphql_etag_pipeline_sha_path(sha)
|
|
|
|
end
|
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
def graphql_project_on_demand_scan_counts_path(project)
|
|
|
|
url_helpers.graphql_etag_project_on_demand_scan_counts_path(project)
|
|
|
|
end
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
# 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
|
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
etag_paths = [
|
|
|
|
project_pipelines_path(project),
|
|
|
|
new_merge_request_pipelines_path(project),
|
|
|
|
graphql_project_on_demand_scan_counts_path(project)
|
|
|
|
]
|
|
|
|
|
|
|
|
etag_paths << commit_pipelines_path(project, pipeline.commit) unless pipeline.commit.nil?
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
each_pipelines_merge_request_path(pipeline) do |path|
|
2022-01-26 12:08:38 +05:30
|
|
|
etag_paths << path
|
2019-07-31 22:56:46 +05:30
|
|
|
end
|
2021-04-17 20:07:23 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
pipeline.upstream_and_all_downstreams.includes(project: [:route, { namespace: :route }]).each do |relative_pipeline| # rubocop: disable CodeReuse/ActiveRecord
|
2022-01-26 12:08:38 +05:30
|
|
|
etag_paths << project_pipeline_path(relative_pipeline.project, relative_pipeline)
|
|
|
|
etag_paths << graphql_pipeline_path(relative_pipeline)
|
|
|
|
etag_paths << graphql_pipeline_sha_path(relative_pipeline.sha)
|
2021-04-17 20:07:23 +05:30
|
|
|
end
|
2022-01-26 12:08:38 +05:30
|
|
|
|
|
|
|
store.touch(*etag_paths)
|
2021-04-17 20:07:23 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def url_helpers
|
|
|
|
@url_helpers ||= UrlHelpers.new
|
2019-07-31 22:56:46 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|