Commit c85f9c5b authored by Francisco Lopez's avatar Francisco Lopez

Code review comments applied

parent 7c7877b5
...@@ -12,6 +12,10 @@ class BaseCountService ...@@ -12,6 +12,10 @@ class BaseCountService
Rails.cache.fetch(cache_key, cache_options) { uncached_count }.to_i Rails.cache.fetch(cache_key, cache_options) { uncached_count }.to_i
end end
def count_stored?
Rails.cache.read(cache_key).present?
end
def refresh_cache(&block) def refresh_cache(&block)
Rails.cache.write(cache_key, block_given? ? yield : uncached_count, raw: raw?) Rails.cache.write(cache_key, block_given? ? yield : uncached_count, raw: raw?)
end end
......
...@@ -12,7 +12,9 @@ module Projects ...@@ -12,7 +12,9 @@ module Projects
def refresh_cache def refresh_cache
@projects.each do |project| @projects.each do |project|
current_count_service(project).refresh_cache { global_count[project.id].to_i } unless current_count_service(project).count_stored?
current_count_service(project).refresh_cache { global_count[project.id].to_i }
end
end end
end end
...@@ -20,8 +22,10 @@ module Projects ...@@ -20,8 +22,10 @@ module Projects
if defined? @service if defined? @service
@service.project = project @service.project = project
else else
count_service.new(project) @service = count_service.new(project)
end end
@service
end end
def global_count(project) def global_count(project)
......
...@@ -64,8 +64,8 @@ module API ...@@ -64,8 +64,8 @@ module API
forked_from_project: [:route, :forks, namespace: :route, tags: :taggings]) forked_from_project: [:route, :forks, namespace: :route, tags: :taggings])
projects = reorder_projects(projects) projects = reorder_projects(projects)
projects = paginate(projects) projects = paginate(projects)
projects_with_fork = projects + projects.map(&:forked_from_project).compact projects_with_forks = projects + projects.map(&:forked_from_project).compact
::Projects::BatchForksCountService.new(projects_with_fork).refresh_cache ::Projects::BatchForksCountService.new(projects_with_forks).refresh_cache
::Projects::BatchOpenIssuesCountService.new(projects).refresh_cache ::Projects::BatchOpenIssuesCountService.new(projects).refresh_cache
projects projects
end 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