Skip to content

Commit 0e4795f

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 0e4795f

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/admin/transfer_crates.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub struct Opts {
2424
pub async fn run(opts: Opts) -> anyhow::Result<()> {
2525
spawn_blocking(move || {
2626
let conn = &mut db::oneoff_connection()?;
27-
conn.transaction(|conn| transfer(opts, conn))?;
27+
transfer(opts, conn)?;
2828
Ok(())
2929
})
3030
.await
@@ -48,14 +48,18 @@ fn transfer(opts: Opts, conn: &mut PgConnection) -> anyhow::Result<()> {
4848
println!("from: {:?}", from.gh_id);
4949
println!("to: {:?}", to.gh_id);
5050

51-
get_confirm("continue?");
51+
if !dialoguer::confirm("continue?") {
52+
return Ok(());
53+
}
5254
}
5355

5456
let prompt = format!(
5557
"Are you sure you want to transfer crates from {} to {}?",
5658
from.gh_login, to.gh_login
5759
);
58-
get_confirm(&prompt);
60+
if !dialoguer::confirm(&prompt) {
61+
return Ok(());
62+
}
5963

6064
let crate_owners = crate_owners::table
6165
.filter(crate_owners::owner_id.eq(from.id))
@@ -71,17 +75,13 @@ fn transfer(opts: Opts, conn: &mut PgConnection) -> anyhow::Result<()> {
7175
}
7276
}
7377

78+
if !dialoguer::confirm("commit?") {
79+
return Ok(());
80+
}
81+
7482
diesel::update(crate_owners)
7583
.set(crate_owners::owner_id.eq(to.id))
7684
.execute(conn)?;
7785

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

0 commit comments

Comments
 (0)