2021-03-11 19:13:27 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Groups
|
|
|
|
# Service class for counting and caching the number of open issues of a group.
|
2021-04-29 21:17:54 +05:30
|
|
|
class OpenIssuesCountService < Groups::CountService
|
2021-11-11 11:23:49 +05:30
|
|
|
# TOTAL_COUNT_KEY includes confidential and hidden issues (admin)
|
|
|
|
# TOTAL_COUNT_WITHOUT_HIDDEN_KEY includes confidential issues but not hidden issues (reporter and above)
|
|
|
|
# PUBLIC_COUNT_WITHOUT_HIDDEN_KEY does not include confidential or hidden issues (guest)
|
|
|
|
TOTAL_COUNT_KEY = 'group_open_issues_including_hidden_count'
|
|
|
|
TOTAL_COUNT_WITHOUT_HIDDEN_KEY = 'group_open_issues_without_hidden_count'
|
|
|
|
PUBLIC_COUNT_WITHOUT_HIDDEN_KEY = 'group_open_public_issues_without_hidden_count'
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
def clear_all_cache_keys
|
2021-11-11 11:23:49 +05:30
|
|
|
[cache_key(TOTAL_COUNT_KEY), cache_key(TOTAL_COUNT_WITHOUT_HIDDEN_KEY), cache_key(PUBLIC_COUNT_WITHOUT_HIDDEN_KEY)].each do |key|
|
2021-06-08 01:23:25 +05:30
|
|
|
Rails.cache.delete(key)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
def cache_key_name
|
2021-11-11 11:23:49 +05:30
|
|
|
if include_hidden?
|
|
|
|
TOTAL_COUNT_KEY
|
|
|
|
elsif public_only?
|
|
|
|
PUBLIC_COUNT_WITHOUT_HIDDEN_KEY
|
|
|
|
else
|
|
|
|
TOTAL_COUNT_WITHOUT_HIDDEN_KEY
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_hidden?
|
|
|
|
strong_memoize(:user_is_admin) do
|
|
|
|
user&.can_admin_all_resources?
|
|
|
|
end
|
2021-03-11 19:13:27 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def public_only?
|
|
|
|
!user_is_at_least_reporter?
|
|
|
|
end
|
|
|
|
|
|
|
|
def user_is_at_least_reporter?
|
|
|
|
strong_memoize(:user_is_at_least_reporter) do
|
|
|
|
group.member?(user, Gitlab::Access::REPORTER)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def relation_for_count
|
2021-06-08 01:23:25 +05:30
|
|
|
IssuesFinder.new(
|
|
|
|
user,
|
|
|
|
group_id: group.id,
|
|
|
|
state: 'opened',
|
|
|
|
non_archived: true,
|
|
|
|
include_subgroups: true,
|
2021-11-11 11:23:49 +05:30
|
|
|
public_only: public_only?,
|
|
|
|
include_hidden: include_hidden?
|
2021-06-08 01:23:25 +05:30
|
|
|
).execute
|
2021-03-11 19:13:27 +05:30
|
|
|
end
|
2021-04-29 21:17:54 +05:30
|
|
|
|
|
|
|
def issuable_key
|
|
|
|
'open_issues'
|
|
|
|
end
|
2021-03-11 19:13:27 +05:30
|
|
|
end
|
|
|
|
end
|