Class: API::Entities::BasicProjectDetails

Inherits:
ProjectIdentity show all
Includes:
ProjectsRelationBuilder, Gitlab::Utils::StrongMemoize
Defined in:
lib/api/entities/basic_project_details.rb

Direct Known Subclasses

Project

Class Method Summary collapse

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


52
53
54
55
56
57
58
# File 'lib/api/entities/basic_project_details.rb', line 52

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(&:forks_count)

  super
end

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

rubocop: disable CodeReuse/ActiveRecord


40
41
42
43
44
45
46
47
48
49
# File 'lib/api/entities/basic_project_details.rb', line 40

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
  projects_relation.preload(:project_feature, :route)
                   .preload(:import_state, :topics)
                   .preload(:auto_devops)
                   .preload(namespace: [:route, :owner])
end