Skip to content

Commit

Permalink
Avoid N+1 queries in rendering project meta
Browse files Browse the repository at this point in the history
  • Loading branch information
coolo committed Dec 20, 2018
1 parent b8f8803 commit 73a0403
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/api/app/views/models/_project.xml.builder
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ xml.project(project_attributes) do

my_model.render_relationships(xml)

repos = my_model.repositories.not_remote.sort { |a, b| b.name <=> a.name }
repos = my_model.repositories.preload(:download_repositories, :release_targets, :hostsystem, path_elements: :link).not_remote.sort { |a, b| b.name <=> a.name }
FlagHelper.render(my_model, xml)

repos.each do |repo|
Expand Down Expand Up @@ -65,10 +65,11 @@ xml.project(project_attributes) do
end
end

unless MaintainedProject.where(maintenance_project_id: my_model.id).empty?
maintained_projects = my_model.maintained_project_names
unless maintained_projects.empty?
xml.maintenance do |maintenance|
MaintainedProject.where(maintenance_project_id: my_model.id).each do |mp|
maintenance.maintains(project: mp.project.name)
maintained_projects.each do |mp|
maintenance.maintains(project: mp)
end
end
end
Expand Down

0 comments on commit 73a0403

Please sign in to comment.