Skip to content

Commit 7512308

Browse files
committed
admin/populate: Convert to async
1 parent 4da2e39 commit 7512308

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/admin/populate.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use crate::{db, schema::version_downloads};
22

3-
use crate::tasks::spawn_blocking;
43
use diesel::prelude::*;
4+
use diesel_async::scoped_futures::ScopedFutureExt;
5+
use diesel_async::{AsyncConnection, AsyncPgConnection, RunQueryDsl};
56
use rand::rngs::StdRng;
67
use rand::{Rng, SeedableRng};
78

@@ -16,15 +17,13 @@ pub struct Opts {
1617
}
1718

1819
pub async fn run(opts: Opts) -> anyhow::Result<()> {
19-
spawn_blocking(move || {
20-
let mut conn = db::oneoff_connection()?;
21-
conn.transaction(|conn| update(opts, conn))?;
22-
Ok(())
23-
})
24-
.await
20+
let mut conn = db::oneoff_async_connection().await?;
21+
conn.transaction(|conn| update(opts, conn).scope_boxed())
22+
.await?;
23+
Ok(())
2524
}
2625

27-
fn update(opts: Opts, conn: &mut PgConnection) -> QueryResult<()> {
26+
async fn update(opts: Opts, conn: &mut AsyncPgConnection) -> QueryResult<()> {
2827
use diesel::dsl::*;
2928

3029
for id in opts.version_ids {
@@ -40,7 +39,8 @@ fn update(opts: Opts, conn: &mut PgConnection) -> QueryResult<()> {
4039
version_downloads::downloads.eq(dls),
4140
version_downloads::date.eq(date(now - day.days())),
4241
))
43-
.execute(conn)?;
42+
.execute(conn)
43+
.await?;
4444
}
4545
}
4646
Ok(())

0 commit comments

Comments
 (0)