Commit cc0fc09c authored by Pavel Shutsin's avatar Pavel Shutsin

Merge branch '357385-uncached-mr-attention-requests-count' into 'master'

Do not cache attention requests count

See merge request gitlab-org/gitlab!84145
parents 82d28610 80586cb7
......@@ -1732,8 +1732,12 @@ class User < ApplicationRecord
end
def attention_requested_open_merge_requests_count(force: false)
Rails.cache.fetch(attention_request_cache_key, force: force, expires_in: COUNT_CACHE_VALIDITY_PERIOD) do
if Feature.enabled?(:uncached_mr_attention_requests_count, self, default_enabled: :yaml)
MergeRequestsFinder.new(self, attention: self.username, state: 'opened', non_archived: true).execute.count
else
Rails.cache.fetch(attention_request_cache_key, force: force, expires_in: COUNT_CACHE_VALIDITY_PERIOD) do
MergeRequestsFinder.new(self, attention: self.username, state: 'opened', non_archived: true).execute.count
end
end
end
......
---
name: uncached_mr_attention_requests_count
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/84145
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/357480
milestone: '14.10'
type: development
group: group::code review
default_enabled: false
......@@ -4988,17 +4988,36 @@ RSpec.describe User do
end
describe '#attention_requested_open_merge_requests_count' do
it 'returns number of open merge requests from non-archived projects' do
user = create(:user)
project = create(:project, :public)
archived_project = create(:project, :public, :archived)
let(:user) { create(:user) }
let(:project) { create(:project, :public) }
let(:archived_project) { create(:project, :public, :archived) }
before do
create(:merge_request, source_project: project, author: user, reviewers: [user])
create(:merge_request, :closed, source_project: project, author: user, reviewers: [user])
create(:merge_request, source_project: archived_project, author: user, reviewers: [user])
end
it 'returns number of open merge requests from non-archived projects' do
expect(Rails.cache).not_to receive(:fetch)
expect(user.attention_requested_open_merge_requests_count(force: true)).to eq 1
end
context 'when uncached_mr_attention_requests_count is disabled' do
before do
stub_feature_flags(uncached_mr_attention_requests_count: false)
end
it 'fetches from cache' do
expect(Rails.cache).to receive(:fetch).with(
user.attention_request_cache_key,
force: false,
expires_in: described_class::COUNT_CACHE_VALIDITY_PERIOD
).and_call_original
expect(user.attention_requested_open_merge_requests_count).to eq 1
end
end
end
describe '#assigned_open_issues_count' do
......
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