Commit e6358d2d authored by Brett Walker's avatar Brett Walker Committed by Nick Thomas

Resolve "Geo: cache results in issue and message count being incorrect"

parent 4897eecb
# Base class for services that count a single resource such as the number of # Base class for services that count a single resource such as the number of
# issues for a project. # issues for a project.
class BaseCountService class BaseCountService
prepend ::EE::BaseCountService
def relation_for_count def relation_for_count
raise( raise(
NotImplementedError, NotImplementedError,
......
---
title: Issue count now refreshes quicker on geo secondary
merge_request: 3639
author:
type: fixed
module EE
module BaseCountService
# geo secondary cache should expire quicker than primary, otherwise various counts
# could be incorrect for 2 weeks.
def cache_options
raise NotImplementedError.new unless defined?(super)
value = super
value[:expires_in] = 20.minutes if ::Gitlab::Geo.secondary?
value
end
end
end
require 'spec_helper'
describe BaseCountService do
include ::EE::GeoHelpers
describe '#cache_options' do
subject { described_class.new.cache_options }
it 'returns the default' do
stub_current_geo_node(nil)
is_expected.to include(:raw)
is_expected.not_to include(:expires_in)
end
it 'returns default on a Geo primary' do
stub_current_geo_node(create(:geo_node, :primary))
is_expected.to include(:raw)
is_expected.not_to include(:expires_in)
end
it 'returns cache of 20 mins on a Geo secondary' do
stub_current_geo_node(create(:geo_node))
is_expected.to include(:raw)
is_expected.to include(expires_in: 20.minutes)
end
end
end
...@@ -15,14 +15,12 @@ describe Users::KeysCountService, :use_clean_rails_memory_store_caching do ...@@ -15,14 +15,12 @@ describe Users::KeysCountService, :use_clean_rails_memory_store_caching do
expect(service.count).to eq(1) expect(service.count).to eq(1)
end end
it 'caches the number of keys in Redis' do it 'caches the number of keys in Redis', :request_store do
service.delete_cache
control_count = ActiveRecord::QueryRecorder.new { service.count }.count
service.delete_cache service.delete_cache
recorder = ActiveRecord::QueryRecorder.new do expect { 2.times { service.count } }.not_to exceed_query_limit(control_count)
2.times { service.count }
end
expect(recorder.count).to eq(1)
end end
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