Skip to content

Eager load Packages::DependencyLink

Context

The npm registry has slow latency for a few endpoints. The Package group conducted an investigation and discovered an n+1 problem. Check out the investigation for additional details and helpful data.

Problem to solve

We have an n+1 issue in the npm package presenter class.

Combine this with the fact that npm metadata endpoints will pull all the versions of the given package.

What happens with packages with 1000+ versions? Yes, you guessed it. 💥

The most straightforward solution is to eager load the related association in the presenter to remove the n+1 problem.

Proposal

  • Update the presenter class to eager load the dependency_links association.
  • Add a n+1 guard spec example.

This is the most straightforward solution. Weighted 1.

Edited by Tim Rizzi