Skip to content

Commit 30c52a2

Browse files
committed
admin/transfer_crates: Remove unnecessary database transaction
There is only a single write query in this code path, so the transaction is somewhat unnecessary. This also simplifies the confirmation code a little bit since it doesn't have to rely on `exit(0)` anymore.
1 parent 429e1be commit 30c52a2

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/admin/transfer_crates.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::{
44
models::{Crate, OwnerKind, User},
55
schema::{crate_owners, crates, users},
66
};
7-
use std::process::exit;
87

98
use crate::tasks::spawn_blocking;
109
use diesel::prelude::*;
@@ -24,7 +23,7 @@ pub struct Opts {
2423
pub async fn run(opts: Opts) -> anyhow::Result<()> {
2524
spawn_blocking(move || {
2625
let conn = &mut db::oneoff_connection()?;
27-
conn.transaction(|conn| transfer(opts, conn))?;
26+
transfer(opts, conn)?;
2827
Ok(())
2928
})
3029
.await
@@ -48,14 +47,18 @@ fn transfer(opts: Opts, conn: &mut PgConnection) -> anyhow::Result<()> {
4847
println!("from: {:?}", from.gh_id);
4948
println!("to: {:?}", to.gh_id);
5049

51-
get_confirm("continue?");
50+
if !dialoguer::confirm("continue?") {
51+
return Ok(());
52+
}
5253
}
5354

5455
let prompt = format!(
5556
"Are you sure you want to transfer crates from {} to {}?",
5657
from.gh_login, to.gh_login
5758
);
58-
get_confirm(&prompt);
59+
if !dialoguer::confirm(&prompt) {
60+
return Ok(());
61+
}
5962

6063
let crate_owners = crate_owners::table
6164
.filter(crate_owners::owner_id.eq(from.id))
@@ -71,17 +74,13 @@ fn transfer(opts: Opts, conn: &mut PgConnection) -> anyhow::Result<()> {
7174
}
7275
}
7376

77+
if !dialoguer::confirm("commit?") {
78+
return Ok(());
79+
}
80+
7481
diesel::update(crate_owners)
7582
.set(crate_owners::owner_id.eq(to.id))
7683
.execute(conn)?;
7784

78-
get_confirm("commit?");
79-
8085
Ok(())
8186
}
82-
83-
fn get_confirm(msg: &str) {
84-
if !dialoguer::confirm(msg) {
85-
exit(0);
86-
}
87-
}

0 commit comments

Comments
 (0)