Commit 625957c2 authored by Felipe Artur's avatar Felipe Artur

BatchOpenIssuesCount only updates public issues count

parent 4ab1011d
...@@ -3,11 +3,10 @@ ...@@ -3,11 +3,10 @@
# because the service use maps to retrieve the project ids # because the service use maps to retrieve the project ids
module Projects module Projects
class BatchOpenIssuesCountService < Projects::BatchCountService class BatchOpenIssuesCountService < Projects::BatchCountService
# Method not needed. Cache here is updated using
# overloaded OpenIssuesCount#refresh_cache method
def global_count def global_count
nil @global_count ||= begin
count_service.query(project_ids).group(:project_id).count
end
end end
def count_service def count_service
......
...@@ -40,19 +40,21 @@ module Projects ...@@ -40,19 +40,21 @@ module Projects
cache_key(TOTAL_COUNT_KEY) cache_key(TOTAL_COUNT_KEY)
end end
# The block passed as parameter is ignored because we need to refresh both
# cache keys on every case.
def refresh_cache(&block) def refresh_cache(&block)
count_grouped_by_confidential = self.class.query(@project, public_only: false).group(:confidential).count if block_given?
public_count = count_grouped_by_confidential[false] || 0 super(&block)
total_count = public_count + (count_grouped_by_confidential[true] || 0) else
count_grouped_by_confidential = self.class.query(@project, public_only: false).group(:confidential).count
public_count = count_grouped_by_confidential[false] || 0
total_count = public_count + (count_grouped_by_confidential[true] || 0)
update_cache_for_key(public_count_cache_key) do update_cache_for_key(public_count_cache_key) do
public_count public_count
end end
update_cache_for_key(total_count_cache_key) do update_cache_for_key(total_count_cache_key) do
total_count total_count
end
end end
end end
......
...@@ -19,8 +19,10 @@ describe Projects::BatchOpenIssuesCountService do ...@@ -19,8 +19,10 @@ describe Projects::BatchOpenIssuesCountService do
it 'refreshes cache keys correctly' do it 'refreshes cache keys correctly' do
subject.refresh_cache subject.refresh_cache
expect(Rails.cache.read(get_cache_key(subject, project_1))).to eq(2) # It does not update total issues cache
expect(Rails.cache.read(get_cache_key(subject, project_2))).to eq(2) expect(Rails.cache.read(get_cache_key(subject, project_1))).to eq(nil)
expect(Rails.cache.read(get_cache_key(subject, project_2))).to eq(nil)
expect(Rails.cache.read(get_cache_key(subject, project_1, true))).to eq(1) expect(Rails.cache.read(get_cache_key(subject, project_1, true))).to eq(1)
expect(Rails.cache.read(get_cache_key(subject, project_1, true))).to eq(1) expect(Rails.cache.read(get_cache_key(subject, project_1, true))).to eq(1)
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