Commit c57ae83d authored by Sean McGivern's avatar Sean McGivern

Fix issuable state counter cache keys

These cache a hash of counts by state, so the state isn't needed in the key
itself.
parent 11f9ac0a
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
# #
class IssuableFinder class IssuableFinder
include CreatedAtFilter include CreatedAtFilter
NONE = '0'.freeze NONE = '0'.freeze
IRRELEVANT_PARAMS_FOR_CACHE_KEY = %i[utf8 sort page].freeze IRRELEVANT_PARAMS_FOR_CACHE_KEY = %i[utf8 sort page].freeze
...@@ -89,8 +89,8 @@ class IssuableFinder ...@@ -89,8 +89,8 @@ class IssuableFinder
execute.find_by!(*params) execute.find_by!(*params)
end end
def state_counter_cache_key(state) def state_counter_cache_key
Digest::SHA1.hexdigest(state_counter_cache_key_components(state).flatten.join('-')) Digest::SHA1.hexdigest(state_counter_cache_key_components.flatten.join('-'))
end end
def group def group
...@@ -417,9 +417,8 @@ class IssuableFinder ...@@ -417,9 +417,8 @@ class IssuableFinder
params[:scope] == 'created-by-me' || params[:scope] == 'authored' || params[:scope] == 'assigned-to-me' params[:scope] == 'created-by-me' || params[:scope] == 'authored' || params[:scope] == 'assigned-to-me'
end end
def state_counter_cache_key_components(state) def state_counter_cache_key_components
opts = params.with_indifferent_access opts = params.with_indifferent_access
opts[:state] = state
opts.except!(*IRRELEVANT_PARAMS_FOR_CACHE_KEY) opts.except!(*IRRELEVANT_PARAMS_FOR_CACHE_KEY)
opts.delete_if { |_, value| value.blank? } opts.delete_if { |_, value| value.blank? }
......
...@@ -75,7 +75,7 @@ class IssuesFinder < IssuableFinder ...@@ -75,7 +75,7 @@ class IssuesFinder < IssuableFinder
current_user.blank? || for_counting || params[:for_counting] current_user.blank? || for_counting || params[:for_counting]
end end
def state_counter_cache_key_components(state) def state_counter_cache_key_components
extra_components = [ extra_components = [
user_can_see_all_confidential_issues?, user_can_see_all_confidential_issues?,
user_cannot_see_confidential_issues?(for_counting: true) user_cannot_see_confidential_issues?(for_counting: true)
......
...@@ -235,7 +235,7 @@ module IssuablesHelper ...@@ -235,7 +235,7 @@ module IssuablesHelper
def issuables_count_for_state(issuable_type, state, finder: nil) def issuables_count_for_state(issuable_type, state, finder: nil)
finder ||= public_send("#{issuable_type}_finder") finder ||= public_send("#{issuable_type}_finder")
cache_key = finder.state_counter_cache_key(state) cache_key = finder.state_counter_cache_key
@counts ||= {} @counts ||= {}
@counts[cache_key] ||= Rails.cache.fetch(cache_key, expires_in: 2.minutes) do @counts[cache_key] ||= Rails.cache.fetch(cache_key, expires_in: 2.minutes) 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