2017-12-01 05:34:24 -05:00
|
|
|
# Service class for getting and caching the number of elements of several projects
|
|
|
|
# Warning: do not user this service with a really large set of projects
|
|
|
|
# because the service use maps to retrieve the project ids.
|
2017-11-24 07:20:52 -05:00
|
|
|
module Projects
|
|
|
|
class BatchCountService
|
|
|
|
def initialize(projects)
|
|
|
|
@projects = projects
|
|
|
|
end
|
|
|
|
|
|
|
|
def refresh_cache
|
|
|
|
@projects.each do |project|
|
2017-11-30 06:52:38 -05:00
|
|
|
service = count_service.new(project)
|
|
|
|
unless service.count_stored?
|
|
|
|
service.refresh_cache { global_count[project.id].to_i }
|
2017-11-24 11:37:02 -05:00
|
|
|
end
|
2017-11-24 07:20:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-30 06:52:38 -05:00
|
|
|
def project_ids
|
|
|
|
@projects.map(&:id)
|
2017-11-24 07:20:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def global_count(project)
|
|
|
|
raise NotImplementedError, 'global_count must be implemented and return an hash indexed by the project id'
|
|
|
|
end
|
|
|
|
|
|
|
|
def count_service
|
|
|
|
raise NotImplementedError, 'count_service must be implemented and return a Projects::CountService object'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|