summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorHiroyuki Sato <sathiroyuki@gmail.com>2019-04-05 22:07:09 +0900
committerHiroyuki Sato <sathiroyuki@gmail.com>2019-04-05 22:47:20 +0900
commit770f721962cd30e930ab7b6e06e9386da6325c3c (patch)
treebcdfa840d1cf0d13694a0be828ac6bf758d11e72 /app
parent074a1797fe581c8eb5cc65bd56af584d5c500688 (diff)
downloadgitlab-ce-770f721962cd30e930ab7b6e06e9386da6325c3c.tar.gz
Refactor: extract duplicate steps to a service class
Diffstat (limited to 'app')
-rw-r--r--app/services/projects/update_statistics_service.rb19
-rw-r--r--app/workers/project_cache_worker.rb5
-rw-r--r--app/workers/update_project_statistics_worker.rb6
3 files changed, 22 insertions, 8 deletions
diff --git a/app/services/projects/update_statistics_service.rb b/app/services/projects/update_statistics_service.rb
new file mode 100644
index 00000000000..f32a779fab0
--- /dev/null
+++ b/app/services/projects/update_statistics_service.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+module Projects
+ class UpdateStatisticsService < BaseService
+ def execute
+ return unless project && project.repository.exists?
+
+ Rails.logger.info("Updating statistics for project #{project.id}")
+
+ project.statistics.refresh!(only: statistics.map(&:to_sym))
+ end
+
+ private
+
+ def statistics
+ params[:statistics]
+ end
+ end
+end
diff --git a/app/workers/project_cache_worker.rb b/app/workers/project_cache_worker.rb
index 5f4972d8f93..b2e0701008a 100644
--- a/app/workers/project_cache_worker.rb
+++ b/app/workers/project_cache_worker.rb
@@ -18,7 +18,7 @@ class ProjectCacheWorker
return unless project && project.repository.exists?
- update_statistics(project, statistics.map(&:to_sym))
+ update_statistics(project, statistics)
project.repository.refresh_method_caches(files.map(&:to_sym))
@@ -34,9 +34,8 @@ class ProjectCacheWorker
return if Gitlab::Database.read_only?
return unless try_obtain_lease_for(project.id, statistics)
- Rails.logger.info("Updating statistics for project #{project.id}")
+ Projects::UpdateStatisticsService.new(project, nil, statistics: statistics).execute
- project.statistics.refresh!(only: statistics)
UpdateProjectStatisticsWorker.perform_in(LEASE_TIMEOUT, project.id, statistics)
end
diff --git a/app/workers/update_project_statistics_worker.rb b/app/workers/update_project_statistics_worker.rb
index 46673c4b07e..9a29cc12707 100644
--- a/app/workers/update_project_statistics_worker.rb
+++ b/app/workers/update_project_statistics_worker.rb
@@ -12,11 +12,7 @@ class UpdateProjectStatisticsWorker
def perform(project_id, statistics = [])
project = Project.find_by(id: project_id)
- return unless project && project.repository.exists?
-
- Rails.logger.info("Updating statistics for project #{project.id}")
-
- project.statistics.refresh!(only: statistics.map(&:to_sym))
+ Projects::UpdateStatisticsService.new(project, nil, statistics: statistics).execute
end
# rubocop: enable CodeReuse/ActiveRecord
end