summaryrefslogtreecommitdiff
path: root/lib/api/projects_relation_builder.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/api/projects_relation_builder.rb')
-rw-r--r--lib/api/projects_relation_builder.rb25
1 files changed, 16 insertions, 9 deletions
diff --git a/lib/api/projects_relation_builder.rb b/lib/api/projects_relation_builder.rb
index 6dfd82d109f..db46602cd90 100644
--- a/lib/api/projects_relation_builder.rb
+++ b/lib/api/projects_relation_builder.rb
@@ -7,28 +7,35 @@ module API
class_methods do
def prepare_relation(projects_relation, options = {})
projects_relation = preload_relation(projects_relation, options)
+
execute_batch_counting(projects_relation)
- # Call the forks count method on every project, so the BatchLoader would load them all at
- # once when the entities are rendered
- projects_relation.each(&:forks_count)
+
+ preload_repository_cache(projects_relation)
projects_relation
end
+ # This is overridden by the specific Entity class to
+ # preload assocations that it needs
def preload_relation(projects_relation, options = {})
projects_relation
end
- def forks_counting_projects(projects_relation)
- projects_relation
+ # This is overridden by the specific Entity class to
+ # batch load certain counts
+ def execute_batch_counting(projects_relation)
end
- def batch_open_issues_counting(projects_relation)
- ::Projects::BatchOpenIssuesCountService.new(projects_relation).refresh_cache
+ 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 execute_batch_counting(projects_relation)
- batch_open_issues_counting(projects_relation)
+ def repositories_for_preload(projects_relation)
+ projects_relation.map(&:repository)
end
end
end