summaryrefslogtreecommitdiff
path: root/app/services/projects/batch_forks_count_service.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/services/projects/batch_forks_count_service.rb')
-rw-r--r--app/services/projects/batch_forks_count_service.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/app/services/projects/batch_forks_count_service.rb b/app/services/projects/batch_forks_count_service.rb
new file mode 100644
index 00000000000..e61fe6c86b2
--- /dev/null
+++ b/app/services/projects/batch_forks_count_service.rb
@@ -0,0 +1,18 @@
+# Service class for getting and caching the number of forks of several projects
+# Warning: do not user this service with a really large set of projects
+# because the service use maps to retrieve the project ids
+module Projects
+ class BatchForksCountService < Projects::BatchCountService
+ def global_count
+ @global_count ||= begin
+ count_service.query(project_ids)
+ .group(:forked_from_project_id)
+ .count
+ end
+ end
+
+ def count_service
+ ::Projects::ForksCountService
+ end
+ end
+end