Class: Projects::BatchCountService
- Inherits:
-
Object
- Object
- Projects::BatchCountService
show all
- Defined in:
- app/services/projects/batch_count_service.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of BatchCountService.
8
9
10
|
# File 'app/services/projects/batch_count_service.rb', line 8
def initialize(projects)
@projects = projects
end
|
Instance Method Details
#count_service ⇒ Object
35
36
37
|
# File 'app/services/projects/batch_count_service.rb', line 35
def count_service
raise NotImplementedError, 'count_service must be implemented and return a Projects::CountService object'
end
|
#global_count(project) ⇒ Object
31
32
33
|
# File 'app/services/projects/batch_count_service.rb', line 31
def global_count(project)
raise NotImplementedError, 'global_count must be implemented and return an hash indexed by the project id'
end
|
#project_ids ⇒ Object
27
28
29
|
# File 'app/services/projects/batch_count_service.rb', line 27
def project_ids
@projects.map(&:id)
end
|
#refresh_cache_and_retrieve_data ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'app/services/projects/batch_count_service.rb', line 12
def refresh_cache_and_retrieve_data
count_services = @projects.map { |project| count_service.new(project) }
services_by_cache_key = count_services.index_by(&:cache_key)
results = Gitlab::Instrumentation::RedisClusterValidator.allow_cross_slot_commands do
Rails.cache.fetch_multi(*services_by_cache_key.keys) do |key|
service = services_by_cache_key[key]
global_count[service.project.id].to_i
end
end
results.transform_keys! { |cache_key| services_by_cache_key[cache_key].project }
end
|