diff options
author | Francisco Lopez <fjlopez@gitlab.com> | 2017-11-24 17:37:02 +0100 |
---|---|---|
committer | Francisco Lopez <fjlopez@gitlab.com> | 2017-12-01 18:32:12 +0100 |
commit | c85f9c5b1d320f7a6f75e3d08bbafd2fb20d3f58 (patch) | |
tree | caad702f39ef47d1a2ec710eb93b776ecd4910ef | |
parent | 7c7877b54dfb0a07bf128102226e338463654431 (diff) | |
download | gitlab-ce-c85f9c5b1d320f7a6f75e3d08bbafd2fb20d3f58.tar.gz |
Code review comments applied
-rw-r--r-- | app/services/base_count_service.rb | 4 | ||||
-rw-r--r-- | app/services/projects/batch_count_service.rb | 8 | ||||
-rw-r--r-- | lib/api/groups.rb | 4 |
3 files changed, 12 insertions, 4 deletions
diff --git a/app/services/base_count_service.rb b/app/services/base_count_service.rb index 2e4fd1db03e..f2844854112 100644 --- a/app/services/base_count_service.rb +++ b/app/services/base_count_service.rb @@ -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 diff --git a/app/services/projects/batch_count_service.rb b/app/services/projects/batch_count_service.rb index 5b69e24b893..b8a030e7bc5 100644 --- a/app/services/projects/batch_count_service.rb +++ b/app/services/projects/batch_count_service.rb @@ -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) diff --git a/lib/api/groups.rb b/lib/api/groups.rb index 05443329a32..83c7898150a 100644 --- a/lib/api/groups.rb +++ b/lib/api/groups.rb @@ -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 |