debian-mirror-gitlab/lib/api/projects_relation_builder.rb

46 lines
1.4 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
module API
module ProjectsRelationBuilder
extend ActiveSupport::Concern
2018-11-20 20:47:30 +05:30
class_methods do
2018-03-17 18:26:18 +05:30
def prepare_relation(projects_relation, options = {})
projects_relation = preload_relation(projects_relation, options)
2021-11-11 11:23:49 +05:30
2018-03-17 18:26:18 +05:30
execute_batch_counting(projects_relation)
2021-11-11 11:23:49 +05:30
preload_repository_cache(projects_relation)
2020-07-28 23:09:34 +05:30
2021-11-18 22:05:49 +05:30
Preloaders::UserMaxAccessLevelInProjectsPreloader.new(projects_relation, options[:current_user]).execute if options[:current_user]
2022-04-04 11:22:00 +05:30
Preloaders::SingleHierarchyProjectGroupPlansPreloader.new(projects_relation).execute if options[:single_hierarchy]
2021-11-18 22:05:49 +05:30
2018-03-17 18:26:18 +05:30
projects_relation
end
2021-11-11 11:23:49 +05:30
# This is overridden by the specific Entity class to
# preload assocations that it needs
2019-03-02 22:35:43 +05:30
def preload_relation(projects_relation, options = {})
2018-03-17 18:26:18 +05:30
projects_relation
end
2021-11-11 11:23:49 +05:30
# This is overridden by the specific Entity class to
# batch load certain counts
def execute_batch_counting(projects_relation)
2018-03-17 18:26:18 +05:30
end
2021-11-11 11:23:49 +05:30
def preload_repository_cache(projects_relation)
repositories = repositories_for_preload(projects_relation)
Gitlab::RepositoryCache::Preloader.new(repositories).preload( # rubocop:disable CodeReuse/ActiveRecord
%i[exists? root_ref has_visible_content? avatar readme_path]
)
2018-03-17 18:26:18 +05:30
end
2021-11-11 11:23:49 +05:30
def repositories_for_preload(projects_relation)
projects_relation.map(&:repository)
2018-03-17 18:26:18 +05:30
end
end
end
end