Class: Projects::OpenIssuesCountService
- Inherits:
-
CountService
show all
- Includes:
- Gitlab::Utils::StrongMemoize
- Defined in:
- app/services/projects/open_issues_count_service.rb
Overview
Service class for counting and caching the number of open issues of a project.
Constant Summary
collapse
- PUBLIC_COUNT_KEY =
Cache keys used to store issues count
'public_open_issues_count'
- TOTAL_COUNT_KEY =
'total_open_issues_count'
Constants inherited
from CountService
CountService::VERSION
Instance Attribute Summary
Attributes inherited from CountService
#project
Class Method Summary
collapse
Instance Method Summary
collapse
#cache_key
#cache_key, #cache_options, #count, #count_stored?, #raw?, #uncached_count, #update_cache_for_key
Constructor Details
Returns a new instance of OpenIssuesCountService.
13
14
15
16
17
|
# File 'app/services/projects/open_issues_count_service.rb', line 13
def initialize(project, user = nil)
@user = user
super(project)
end
|
Class Method Details
.query(projects, public_only: true) ⇒ Object
We only show issues count including confidential for planners, who are allowed to view confidential issues. This will still show a discrepancy on issues number but should be less than before. Check gitlab.com/gitlab-org/gitlab-foss/issues/38418 description.
70
71
72
73
74
75
76
77
78
|
# File 'app/services/projects/open_issues_count_service.rb', line 70
def self.query(projects, public_only: true)
open_issues = Issue.opened.without_hidden
if public_only
open_issues.public_only.where(project: projects)
else
open_issues.where(project: projects)
end
end
|
Instance Method Details
#cache_key_name ⇒ Object
19
20
21
|
# File 'app/services/projects/open_issues_count_service.rb', line 19
def cache_key_name
public_only? ? PUBLIC_COUNT_KEY : TOTAL_COUNT_KEY
end
|
#delete_cache ⇒ Object
60
61
62
63
64
|
# File 'app/services/projects/open_issues_count_service.rb', line 60
def delete_cache
[public_count_cache_key, total_count_cache_key].each do |key|
Rails.cache.delete(key)
end
end
|
#public_count_cache_key ⇒ Object
37
38
39
|
# File 'app/services/projects/open_issues_count_service.rb', line 37
def public_count_cache_key
cache_key(PUBLIC_COUNT_KEY)
end
|
#public_only? ⇒ Boolean
23
24
25
|
# File 'app/services/projects/open_issues_count_service.rb', line 23
def public_only?
!user_is_at_least_planner?
end
|
#refresh_cache(&block) ⇒ Object
rubocop: disable CodeReuse/ActiveRecord
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'app/services/projects/open_issues_count_service.rb', line 46
def refresh_cache(&block)
count_grouped_by_confidential = self.class.query(@project, public_only: false).group(:confidential).count
public_count = count_grouped_by_confidential[false] || 0
total_count = public_count + (count_grouped_by_confidential[true] || 0)
update_cache_for_key(public_count_cache_key) do
public_count
end
update_cache_for_key(total_count_cache_key) do
total_count
end
end
|
#relation_for_count ⇒ Object
33
34
35
|
# File 'app/services/projects/open_issues_count_service.rb', line 33
def relation_for_count
self.class.query(@project, public_only: public_only?)
end
|
#total_count_cache_key ⇒ Object
41
42
43
|
# File 'app/services/projects/open_issues_count_service.rb', line 41
def total_count_cache_key
cache_key(TOTAL_COUNT_KEY)
end
|
#user_is_at_least_planner? ⇒ Boolean
27
28
29
30
31
|
# File 'app/services/projects/open_issues_count_service.rb', line 27
def user_is_at_least_planner?
strong_memoize(:user_is_at_least_planner) do
@project.member?(@user, Gitlab::Access::PLANNER)
end
end
|