Use Etag caching for pipelines json
Enable caching in the Etag::Middleware and when a pipeline changes status, expire the cache for the project pipelines path.
This commit is contained in:
parent
ebae10467d
commit
847b9c8232
|
@ -88,6 +88,8 @@ module Ci
|
|||
|
||||
pipeline.run_after_commit do
|
||||
PipelineHooksWorker.perform_async(id)
|
||||
Ci::ExpirePipelineCacheService.new(project, nil)
|
||||
.execute(pipeline)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
module Ci
|
||||
class ExpirePipelineCacheService < BaseService
|
||||
def execute(pipeline)
|
||||
@pipeline = pipeline
|
||||
|
||||
Gitlab::EtagCaching::Store.new.touch(project_pipelines_path)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def project_pipelines_path
|
||||
Gitlab::Routing.url_helpers.namespace_project_pipelines_path(
|
||||
project.namespace,
|
||||
project,
|
||||
format: :json)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -10,6 +10,10 @@ module Gitlab
|
|||
{
|
||||
regexp: %r(^(?!.*(#{RESERVED_WORDS})).*/issues/\d+/rendered_title\z),
|
||||
name: 'issue_title'
|
||||
},
|
||||
{
|
||||
regexp: %r(^(?!.*(#{RESERVED_WORDS})).*/pipelines\.json\z),
|
||||
name: 'project_pipelines'
|
||||
}
|
||||
].freeze
|
||||
|
||||
|
|
|
@ -335,6 +335,14 @@ describe Ci::Pipeline, models: true do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'pipeline ETag caching' do
|
||||
it 'executes ExpirePipelinesCacheService' do
|
||||
expect_any_instance_of(Ci::ExpirePipelineCacheService).to receive(:execute).with(pipeline)
|
||||
|
||||
pipeline.cancel
|
||||
end
|
||||
end
|
||||
|
||||
def create_build(name, queued_at = current, started_from = 0)
|
||||
create(:ci_build,
|
||||
name: name,
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Ci::ExpirePipelineCacheService, services: true do
|
||||
let(:user) { create(:user) }
|
||||
let(:project) { create(:empty_project) }
|
||||
let(:pipeline) { create(:ci_pipeline, project: project) }
|
||||
subject { described_class.new(project, user) }
|
||||
|
||||
describe '#execute' do
|
||||
it 'invalidate Etag caching for project pipelines path' do
|
||||
path = "/#{project.full_path}/pipelines.json"
|
||||
|
||||
expect_any_instance_of(Gitlab::EtagCaching::Store).to receive(:touch).with(path)
|
||||
|
||||
subject.execute(pipeline)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue