提交 c85f9c5b 编写于 作者: F Francisco Lopez

Code review comments applied

上级 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,7 +12,9 @@ module Projects
def refresh_cache
@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
......@@ -20,8 +22,10 @@ module Projects
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% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册