Commit 847b9c82 authored by Toon Claes's avatar Toon Claes Committed by Kamil Trzcinski

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.
parent ebae1046
......@@ -88,6 +88,8 @@ module Ci
pipeline.run_after_commit do
PipelineHooksWorker.perform_async(id)
Ci::ExpirePipelineCacheService.new(project, nil)
.execute(pipeline)
end
end
......
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,
......
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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment