Commit 2d233dac authored by Stan Hu's avatar Stan Hu

Clear pipeline status cache after destruction of pipeline

`project.pipeline_status.has_status?` is cached, which can lead to Error
500s in the UI if the this condition is used to check whether a pipeline
exists for a commit. We now expire the cache to ensure that the
information is consistent.

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/59453
parent 61b2f70f
...@@ -6,6 +6,8 @@ module Ci ...@@ -6,6 +6,8 @@ module Ci
raise Gitlab::Access::AccessDeniedError unless can?(current_user, :destroy_pipeline, pipeline) raise Gitlab::Access::AccessDeniedError unless can?(current_user, :destroy_pipeline, pipeline)
pipeline.destroy! pipeline.destroy!
Gitlab::Cache::Ci::ProjectPipelineStatus.new(pipeline.project).delete_from_cache
end end
end end
end end
---
title: Clear pipeline status cache after destruction of pipeline
merge_request: 26575
author:
type: fixed
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
require 'spec_helper' require 'spec_helper'
describe ::Ci::DestroyPipelineService do describe ::Ci::DestroyPipelineService do
let(:project) { create(:project) } let(:project) { create(:project, :repository) }
let!(:pipeline) { create(:ci_pipeline, project: project) } let!(:pipeline) { create(:ci_pipeline, :success, project: project, sha: project.commit.id) }
subject { described_class.new(project, user).execute(pipeline) } subject { described_class.new(project, user).execute(pipeline) }
...@@ -17,6 +17,17 @@ describe ::Ci::DestroyPipelineService do ...@@ -17,6 +17,17 @@ describe ::Ci::DestroyPipelineService do
expect { pipeline.reload }.to raise_error(ActiveRecord::RecordNotFound) expect { pipeline.reload }.to raise_error(ActiveRecord::RecordNotFound)
end end
it 'clears the cache', :use_clean_rails_memory_store_caching do
create(:commit_status, :success, pipeline: pipeline, ref: pipeline.ref)
expect(project.pipeline_status.has_status?).to be_truthy
subject
# Need to use find to avoid memoization
expect(Project.find(project.id).pipeline_status.has_status?).to be_falsey
end
it 'does not log an audit event' do it 'does not log an audit event' do
expect { subject }.not_to change { SecurityEvent.count } expect { subject }.not_to change { SecurityEvent.count }
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