Package versions rendering results in N^2 queries

Summary

The package list API results in an N+1 query due to a combination of the versions and pipeline info being exposed.

Steps to reproduce

Create a few packages using a pipeline, with each pipeline updating the version of the package, then request the package index for that project.

What is the current bug behavior?

If a package in a project has 10 versions, when getting the list results for that package,

  1. First, the build_info is queried for each package (1 query)
  2. For each version, the build_info is queried a second time (9 queries)
  3. Since each version is actually it's own package record, step 1 and step 2 each happen 10 times. (10 queries per package -> 100 total queries)

This results in an N*N or N^2 problem.

Relevant logs and/or screenshots

Possible fixes

We should preload build_info when rendering packages in the API so we remove all of the build_info queries.

Edited by Steve Abrams