summaryrefslogtreecommitdiff
path: root/app/finders
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2017-06-29 12:43:56 +0100
committerSean McGivern <sean@gitlab.com>2017-06-30 10:33:46 +0100
commit0c6cdd07829668e04012219eb21cc60db8c1eabc (patch)
tree3d6eca853345bd56ba2939b950296a6c2cb68f36 /app/finders
parent8deece32478aaa83354fcfff7b5d6f3250d55844 (diff)
downloadgitlab-ce-0c6cdd07829668e04012219eb21cc60db8c1eabc.tar.gz
Make finders responsible for counter cache keys
Diffstat (limited to 'app/finders')
-rw-r--r--app/finders/issuable_finder.rb14
-rw-r--r--app/finders/issues_finder.rb23
2 files changed, 31 insertions, 6 deletions
diff --git a/app/finders/issuable_finder.rb b/app/finders/issuable_finder.rb
index e8605f3d5b3..7bc2117f61e 100644
--- a/app/finders/issuable_finder.rb
+++ b/app/finders/issuable_finder.rb
@@ -20,6 +20,7 @@
#
class IssuableFinder
NONE = '0'.freeze
+ IRRELEVANT_PARAMS_FOR_CACHE_KEY = %i[utf8 sort page].freeze
attr_accessor :current_user, :params
@@ -86,6 +87,10 @@ class IssuableFinder
execute.find_by!(*params)
end
+ def state_counter_cache_key(state)
+ Digest::SHA1.hexdigest(state_counter_cache_key_components(state).flatten.join('-'))
+ end
+
def group
return @group if defined?(@group)
@@ -418,4 +423,13 @@ class IssuableFinder
def current_user_related?
params[:scope] == 'created-by-me' || params[:scope] == 'authored' || params[:scope] == 'assigned-to-me'
end
+
+ def state_counter_cache_key_components(state)
+ opts = params.with_indifferent_access
+ opts[:state] = state
+ opts.except!(*IRRELEVANT_PARAMS_FOR_CACHE_KEY)
+ opts.delete_if { |_, value| value.blank? }
+
+ ['issuables_count', klass.to_ability_name, opts.sort]
+ end
end
diff --git a/app/finders/issues_finder.rb b/app/finders/issues_finder.rb
index b213a7aebfd..d20f4475a03 100644
--- a/app/finders/issues_finder.rb
+++ b/app/finders/issues_finder.rb
@@ -22,7 +22,7 @@ class IssuesFinder < IssuableFinder
Issue
end
- def not_restricted_by_confidentiality
+ def with_confidentiality_access_check
return Issue.all if user_can_see_all_confidential_issues?
return Issue.where('issues.confidential IS NOT TRUE') if user_cannot_see_confidential_issues?
@@ -36,7 +36,15 @@ class IssuesFinder < IssuableFinder
project_ids: current_user.authorized_projects(CONFIDENTIAL_ACCESS_LEVEL).select(:id))
end
+ private
+
+ def init_collection
+ with_confidentiality_access_check
+ end
+
def user_can_see_all_confidential_issues?
+ return @user_can_see_all_confidential_issues if defined?(@user_can_see_all_confidential_issues)
+
return @user_can_see_all_confidential_issues = false if current_user.blank?
return @user_can_see_all_confidential_issues = true if current_user.full_private_access?
@@ -46,16 +54,19 @@ class IssuesFinder < IssuableFinder
project.team.max_member_access(current_user.id) >= CONFIDENTIAL_ACCESS_LEVEL
end
- def user_cannot_see_confidential_issues?
+ def user_cannot_see_confidential_issues?(for_counting: false)
return false if user_can_see_all_confidential_issues?
- current_user.blank? || params[:for_counting]
+ current_user.blank? || for_counting || params[:for_counting]
end
- private
+ def state_counter_cache_key_components(state)
+ extra_components = [
+ user_can_see_all_confidential_issues?,
+ user_cannot_see_confidential_issues?(for_counting: true)
+ ]
- def init_collection
- not_restricted_by_confidentiality
+ super + extra_components
end
def by_assignee(items)