Skip to content

publish: Avoid N+1 query in add_dependencies() #7230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2023

Conversation

Turbo87
Copy link
Member

@Turbo87 Turbo87 commented Oct 3, 2023

Before this change we were sending out a query for each added dependency, just to look up the corresponding id and check if the dependency exists on crates.io. With longer lists of dependencies this behavior is quite wasteful and commonly referred to as an N+1 query.

After this change we send out a single query with all dependency names, save the resulting name, id tuples to an in-memory HashMap and then use that map inside the loop to check if the corresponding crate exists.

@Turbo87 Turbo87 added C-internal 🔧 Category: Nonessential work that would make the codebase more consistent or clear A-backend ⚙️ labels Oct 3, 2023
Before this change we were sending out a query for each added dependency, just to look up the corresponding `id` and check if the dependency exists on crates.io. With longer lists of dependencies this behavior is quite wasteful and commonly referred to as an N+1 query.

After this change we send out a single query with all dependency names, save the resulting `name, id` tuples to an in-memory `HashMap` and then use that map inside the loop to check if the corresponding crate exists.
@Turbo87 Turbo87 enabled auto-merge (squash) October 3, 2023 11:08
@Turbo87 Turbo87 merged commit 6478354 into rust-lang:main Oct 3, 2023
@Turbo87 Turbo87 deleted the n-plus-one branch October 3, 2023 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-backend ⚙️ C-internal 🔧 Category: Nonessential work that would make the codebase more consistent or clear
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant