summaryrefslogtreecommitdiff
path: root/lib/api/projects_relation_builder.rb
blob: 9fd79c491c2ba2d4e9335d0a454eb916e3ae5311 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
module API
  module ProjectsRelationBuilder
    extend ActiveSupport::Concern

    class_methods do
      def prepare_relation(projects_relation, options = {})
        projects_relation = preload_relation(projects_relation, options)
        execute_batch_counting(projects_relation)
        projects_relation
      end

      def preload_relation(projects_relation, options =  {})
        projects_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