2019-12-12 22:07:50 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module API
|
|
|
|
module ProjectsRelationBuilder
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
class_methods do
|
|
|
|
def prepare_relation(projects_relation, options = {})
|
|
|
|
projects_relation = preload_relation(projects_relation, options)
|
2021-09-08 08:12:01 -04:00
|
|
|
|
2019-12-12 22:07:50 -05:00
|
|
|
execute_batch_counting(projects_relation)
|
2020-07-09 11:08:59 -04:00
|
|
|
|
2021-09-09 23:10:59 -04:00
|
|
|
preload_repository_cache(projects_relation)
|
|
|
|
|
2021-10-05 11:12:53 -04:00
|
|
|
Preloaders::UserMaxAccessLevelInProjectsPreloader.new(projects_relation, options[:current_user]).execute if options[:current_user]
|
|
|
|
|
2019-12-12 22:07:50 -05:00
|
|
|
projects_relation
|
|
|
|
end
|
|
|
|
|
2021-09-08 08:12:01 -04:00
|
|
|
# This is overridden by the specific Entity class to
|
|
|
|
# preload assocations that it needs
|
2019-12-12 22:07:50 -05:00
|
|
|
def preload_relation(projects_relation, options = {})
|
|
|
|
projects_relation
|
|
|
|
end
|
|
|
|
|
2021-09-08 08:12:01 -04:00
|
|
|
# This is overridden by the specific Entity class to
|
|
|
|
# batch load certain counts
|
2019-12-12 22:07:50 -05:00
|
|
|
def execute_batch_counting(projects_relation)
|
|
|
|
end
|
2021-09-09 23:10:59 -04:00
|
|
|
|
|
|
|
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]
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def repositories_for_preload(projects_relation)
|
|
|
|
projects_relation.map(&:repository)
|
|
|
|
end
|
2019-12-12 22:07:50 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|