Commit dec0c7a9 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '197320-clear-cache-after-sentry-error-update' into 'master'

Resolve "Clear Error Tracking cache on demand"

Closes #197320

See merge request gitlab-org/gitlab!23368
parents e8ee44ed 91f0c33a
......@@ -126,6 +126,10 @@ module ErrorTracking
end
end
def expire_issues_cache
Rails.cache.delete_matched(expand_cache_key('list_issues'))
end
# http://HOST/api/0/projects/ORG/PROJECT
# ->
# http://HOST/ORG/PROJECT
......@@ -142,6 +146,12 @@ module ErrorTracking
private
def expand_cache_key(resource_prefix)
klass_key = self.class.reactive_cache_key.call(self).join(':')
"#{klass_key}:#{resource_prefix}*"
end
def add_gitlab_issue_details(issue)
issue.gitlab_commit = match_gitlab_commit(issue.first_release_version)
issue.gitlab_commit_path = project_commit_path(project, issue.gitlab_commit) if issue.gitlab_commit
......
......@@ -2,6 +2,8 @@
module ErrorTracking
class IssueUpdateService < ErrorTracking::BaseService
include ::Gitlab::Utils::StrongMemoize
private
def perform
......@@ -9,6 +11,7 @@ module ErrorTracking
unless parse_errors(response).present?
response[:closed_issue_iid] = update_related_issue&.iid
project_error_tracking_setting.expire_issues_cache
end
response
......@@ -22,10 +25,9 @@ module ErrorTracking
end
def update_related_issue
issue = related_issue
return unless issue
return if related_issue.nil?
close_and_create_note(issue)
close_and_create_note(related_issue)
end
def close_and_create_note(issue)
......@@ -49,11 +51,13 @@ module ErrorTracking
end
def related_issue
strong_memoize(:related_issue) do
SentryIssueFinder
.new(project, current_user: current_user)
.execute(params[:issue_id])
&.issue
end
end
def resolving?
update_params[:status] == 'resolved'
......
......@@ -440,4 +440,18 @@ describe ErrorTracking::ProjectErrorTrackingSetting do
end
end
end
describe '#expire_issues_cache', :use_clean_rails_memory_store_caching do
it 'clears the cache' do
klass_key = subject.class.reactive_cache_key.call(subject).join(':')
key = "#{klass_key}:list_issues:some_suffix"
Rails.cache.write(key, 1)
expect(Rails.cache.exist?(key)).to eq(true)
subject.expire_issues_cache
expect(Rails.cache.exist?(key)).to eq(false)
end
end
end
......@@ -40,6 +40,16 @@ describe ErrorTracking::IssueUpdateService do
result
end
it 'clears the reactive cache' do
allow(error_tracking_setting)
.to receive(:expire_issues_cache)
result
expect(error_tracking_setting)
.to have_received(:expire_issues_cache)
end
context 'related issue and resolving' do
let(:issue) { create(:issue, project: project) }
let(:sentry_issue) { create(:sentry_issue, issue: issue) }
......
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