Class: API::Entities::Project

Inherits:
BasicProjectDetails show all
Includes:
Helpers::RelatedResourcesHelpers
Defined in:
lib/api/entities/project.rb

Direct Known Subclasses

ProjectWithAccess

Class Method Summary collapse

Methods included from Helpers::RelatedResourcesHelpers

#expose_path, #expose_url, #issues_available?, #mrs_available?

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Class Method Details

.execute_batch_counting(projects_relation) ⇒ Object

rubocop: enable CodeReuse/ActiveRecord


168
169
170
171
172
173
174
175
# File 'lib/api/entities/project.rb', line 168

def self.execute_batch_counting(projects_relation)
  # Call the count methods on every project, so the BatchLoader would load them all at
  # once when the entities are rendered
  projects_relation.each(&:open_issues_count)
  projects_relation.map(&:forked_from_project).compact.each(&:forks_count)

  super
end

.preload_relation(projects_relation, options = {}) ⇒ Object


150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/api/entities/project.rb', line 150

def self.preload_relation(projects_relation, options = {})
  # Preloading topics, should be done with using only `:topics`,
  # as `:topics` are defined as: `has_many :topics, through: :project_topics`
  # N+1 is solved then by using `subject.topics.map(&:name)`
  # MR describing the solution: https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/20555
  super(projects_relation).preload(group: :namespace_settings)
                          .preload(:ci_cd_settings)
                          .preload(:project_setting)
                          .preload(:container_expiration_policy)
                          .preload(:auto_devops)
                          .preload(:service_desk_setting)
                          .preload(project_group_links: { group: :route },
                                   fork_network: :root_project,
                                   fork_network_member: :forked_from_project,
                                   forked_from_project: [:route, :topics, :group, :project_feature, namespace: [:route, :owner]])
end

.preload_resource(project) ⇒ Object

rubocop: disable CodeReuse/ActiveRecord


146
147
148
# File 'lib/api/entities/project.rb', line 146

def self.preload_resource(project)
  ActiveRecord::Associations::Preloader.new.preload(project, project_group_links: { group: :route })
end

.repositories_for_preload(projects_relation) ⇒ Object


177
178
179
# File 'lib/api/entities/project.rb', line 177

def self.repositories_for_preload(projects_relation)
  super + projects_relation.map(&:forked_from_project).compact.map(&:repository)
end