Skip to content

Commit 3aeff80

Browse files
committed
admin/delete_crate: Remove unnecessary HashMap
The number of deleted crates is usually no more than a dozen or two, so the extra complexity from the `HashMap` isn't really worth it here.
1 parent 3c4d3cc commit 3aeff80

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

src/bin/crates-admin/delete_crate.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ use diesel::expression::SqlLiteral;
1010
use diesel::prelude::*;
1111
use diesel::sql_types::{Array, BigInt, Text};
1212
use diesel_async::RunQueryDsl;
13-
use futures_util::TryStreamExt;
14-
use std::collections::HashMap;
1513
use std::fmt::Display;
1614

1715
#[derive(clap::Parser, Debug)]
@@ -42,19 +40,14 @@ pub async fn run(opts: Opts) -> anyhow::Result<()> {
4240
.inner_join(crate_downloads::table)
4341
.filter(crates::name.eq_any(&crate_names))
4442
.select(CrateInfo::as_select())
45-
.load_stream::<CrateInfo>(&mut conn)
43+
.load::<CrateInfo>(&mut conn)
4644
.await
47-
.context("Failed to look up crate name from the database")?
48-
.try_fold(HashMap::new(), |mut map, info| {
49-
map.insert(info.name.clone(), info);
50-
futures_util::future::ready(Ok(map))
51-
})
52-
.await?;
45+
.context("Failed to look up crate name from the database")?;
5346

5447
println!("Deleting the following crates:");
5548
println!();
5649
for name in &crate_names {
57-
match existing_crates.get(name) {
50+
match existing_crates.iter().find(|info| info.name == *name) {
5851
Some(info) => println!(" - {} ({info})", name.bold()),
5952
None => println!(" - {name} (⚠️ crate not found)"),
6053
}
@@ -68,7 +61,7 @@ pub async fn run(opts: Opts) -> anyhow::Result<()> {
6861
}
6962

7063
for name in &crate_names {
71-
if let Some(crate_info) = existing_crates.get(name) {
64+
if let Some(crate_info) = existing_crates.iter().find(|info| info.name == *name) {
7265
let id = crate_info.id;
7366

7467
info!("{name}: Deleting crate from the database…");

0 commit comments

Comments
 (0)