diff options
author | Francisco Lopez <fjlopez@gitlab.com> | 2017-11-27 12:24:33 +0100 |
---|---|---|
committer | Francisco Lopez <fjlopez@gitlab.com> | 2017-12-01 18:32:12 +0100 |
commit | 58c5b463ff75618a557d067c16f49ef581cda85c (patch) | |
tree | 6de7fc1cb446b6120e8eb6c777912904b77efffd /lib/api/projects_relation_builder.rb | |
parent | c85f9c5b1d320f7a6f75e3d08bbafd2fb20d3f58 (diff) | |
download | gitlab-ce-58c5b463ff75618a557d067c16f49ef581cda85c.tar.gz |
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.rb | 34 |
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 |