2021-01-20 19:11:07 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Groups
|
|
|
|
# Service class for counting and caching the number of open issues of a group.
|
2021-03-29 17:09:08 -04:00
|
|
|
class OpenIssuesCountService < Groups::CountService
|
2022-04-25 11:08:44 -04:00
|
|
|
PUBLIC_COUNT_KEY = 'group_public_open_issues_count'
|
|
|
|
TOTAL_COUNT_KEY = 'group_total_open_issues_count'
|
2021-01-20 19:11:07 -05:00
|
|
|
|
2021-04-30 08:12:30 -04:00
|
|
|
def clear_all_cache_keys
|
2022-04-25 11:08:44 -04:00
|
|
|
[cache_key(PUBLIC_COUNT_KEY), cache_key(TOTAL_COUNT_KEY)].each do |key|
|
2021-04-30 08:12:30 -04:00
|
|
|
Rails.cache.delete(key)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-20 19:11:07 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def cache_key_name
|
2022-04-25 11:08:44 -04:00
|
|
|
public_only? ? PUBLIC_COUNT_KEY : TOTAL_COUNT_KEY
|
2021-01-20 19:11:07 -05:00
|
|
|
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-04-30 08:12:30 -04:00
|
|
|
IssuesFinder.new(
|
|
|
|
user,
|
|
|
|
group_id: group.id,
|
|
|
|
state: 'opened',
|
|
|
|
non_archived: true,
|
|
|
|
include_subgroups: true,
|
2022-04-25 11:08:44 -04:00
|
|
|
public_only: public_only?
|
2021-04-30 08:12:30 -04:00
|
|
|
).execute
|
2021-01-20 19:11:07 -05:00
|
|
|
end
|
2021-03-29 17:09:08 -04:00
|
|
|
|
|
|
|
def issuable_key
|
|
|
|
'open_issues'
|
|
|
|
end
|
2021-01-20 19:11:07 -05:00
|
|
|
end
|
|
|
|
end
|