Skip to content
Snippets Groups Projects

Refactor project API helpers

Merged Andreas Brandl requested to merge ab/pagination-batch-counts into master
Files
4
+ 10
9
@@ -176,7 +176,6 @@ class ProjectImportStatus < ProjectIdentity
end
class BasicProjectDetails < ProjectIdentity
include ::API::ProjectsRelationBuilder
include ::API::ProjectsBatchCounting
expose :default_branch, if: -> (project, options) { Ability.allowed?(options[:current_user], :download_code, project) }
@@ -212,6 +211,14 @@ class BasicProjectDetails < ProjectIdentity
expose :namespace, using: 'API::Entities::NamespaceBasic'
expose :custom_attributes, using: 'API::Entities::CustomAttribute', if: :with_custom_attributes
# This adds preloading to the query and executes batch counting
# Side-effect: The query will be executed during batch counting
def self.prepare!(projects_relation)
preload_relation(projects_relation).tap do |projects|
execute_batch_counting(projects)
end
end
# rubocop: disable CodeReuse/ActiveRecord
def self.preload_relation(projects_relation, options = {})
# Preloading tags, should be done with using only `:tags`,
@@ -419,10 +426,7 @@ class GroupDetail < Group
options: { only_owned: true }
).execute
Entities::Project.prepare_relation(projects).tap do |projects|
# Refresh count caches
Entities::Project.execute_batch_counting(projects)
end
Entities::Project.prepare!(projects)
end
expose :shared_projects, using: Entities::Project do |group, options|
@@ -432,10 +436,7 @@ class GroupDetail < Group
options: { only_shared: true }
).execute
Entities::Project.prepare_relation(projects).tap do |projects|
# Refresh count caches
Entities::Project.execute_batch_counting(projects)
end
Entities::Project.prepare!(projects)
end
end
Loading