Commit c85f9c5b authored by Francisco Lopez's avatar Francisco Lopez

Code review comments applied

parent 7c7877b5
......@@ -12,6 +12,10 @@ class BaseCountService
Rails.cache.fetch(cache_key, cache_options) { uncached_count }.to_i
end
def count_stored?
Rails.cache.read(cache_key).present?
end
def refresh_cache(&block)
Rails.cache.write(cache_key, block_given? ? yield : uncached_count, raw: raw?)
end
......
......@@ -12,16 +12,20 @@ module Projects
def refresh_cache
@projects.each do |project|
unless current_count_service(project).count_stored?
current_count_service(project).refresh_cache { global_count[project.id].to_i }
end
end
end
def current_count_service(project)
if defined? @service
@service.project = project
else
count_service.new(project)
@service = count_service.new(project)
end
@service
end
def global_count(project)
......
......@@ -64,8 +64,8 @@ module API
forked_from_project: [:route, :forks, namespace: :route, tags: :taggings])
projects = reorder_projects(projects)
projects = paginate(projects)
projects_with_fork = projects + projects.map(&:forked_from_project).compact
::Projects::BatchForksCountService.new(projects_with_fork).refresh_cache
projects_with_forks = projects + projects.map(&:forked_from_project).compact
::Projects::BatchForksCountService.new(projects_with_forks).refresh_cache
::Projects::BatchOpenIssuesCountService.new(projects).refresh_cache
projects
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment