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

BatchOpenIssuesCount only updates public issues count

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