summaryrefslogtreecommitdiff
path: root/lib/api/projects_relation_builder.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-09-20 13:18:24 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-09-20 13:18:24 +0000
commit0653e08efd039a5905f3fa4f6e9cef9f5d2f799c (patch)
tree4dcc884cf6d81db44adae4aa99f8ec1233a41f55 /lib/api/projects_relation_builder.rb
parent744144d28e3e7fddc117924fef88de5d9674fe4c (diff)
downloadgitlab-ce-14.3.0-rc42.tar.gz
Add latest changes from gitlab-org/gitlab@14-3-stable-eev14.3.0-rc42
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