Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancisco Lopez <fjlopez@gitlab.com>2017-11-27 14:24:33 +0300
committerFrancisco Lopez <fjlopez@gitlab.com>2017-12-01 20:32:12 +0300
commit58c5b463ff75618a557d067c16f49ef581cda85c (patch)
tree6de7fc1cb446b6120e8eb6c777912904b77efffd /lib/api/projects_relation_builder.rb
parentc85f9c5b1d320f7a6f75e3d08bbafd2fb20d3f58 (diff)
Refactored /projects and /user/:user_id/projects endpoints
Diffstat (limited to 'lib/api/projects_relation_builder.rb')
-rw-r--r--lib/api/projects_relation_builder.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/api/projects_relation_builder.rb b/lib/api/projects_relation_builder.rb
new file mode 100644
index 00000000000..57df6157225
--- /dev/null
+++ b/lib/api/projects_relation_builder.rb
@@ -0,0 +1,34 @@
+module API
+ module ProjectsRelationBuilder
+ extend ActiveSupport::Concern
+
+ module ClassMethods
+ def prepare_relation(relation)
+ relation = preload_relation(relation)
+ execute_batch_counting(relation)
+ relation
+ end
+
+ def preload_relation(relation)
+ raise NotImplementedError, 'self.preload_relation method must be defined and return a relation'
+ end
+
+ def forks_counting_projects(projects_relation)
+ projects_relation
+ end
+
+ def batch_forks_counting(projects_relation)
+ ::Projects::BatchForksCountService.new(forks_counting_projects(projects_relation)).refresh_cache
+ end
+
+ def batch_open_issues_counting(projects_relation)
+ ::Projects::BatchOpenIssuesCountService.new(projects_relation).refresh_cache
+ end
+
+ def execute_batch_counting(projects_relation)
+ batch_forks_counting(projects_relation)
+ batch_open_issues_counting(projects_relation)
+ end
+ end
+ end
+end