Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions src/admin/populate.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use crate::{db, schema::version_downloads};

use crate::tasks::spawn_blocking;
use diesel::prelude::*;
use rand::{thread_rng, Rng};
use diesel_async::scoped_futures::ScopedFutureExt;
use diesel_async::{AsyncConnection, AsyncPgConnection, RunQueryDsl};
use rand::rngs::StdRng;
use rand::{Rng, SeedableRng};

#[derive(clap::Parser, Debug)]
#[command(
Expand All @@ -15,19 +17,17 @@
}

pub async fn run(opts: Opts) -> anyhow::Result<()> {
spawn_blocking(move || {
let mut conn = db::oneoff_connection()?;
conn.transaction(|conn| update(opts, conn))?;
Ok(())
})
.await
let mut conn = db::oneoff_async_connection().await?;
conn.transaction(|conn| update(opts, conn).scope_boxed())
.await?;
Ok(())

Check warning on line 23 in src/admin/populate.rs

View check run for this annotation

Codecov / codecov/patch

src/admin/populate.rs#L20-L23

Added lines #L20 - L23 were not covered by tests
}

fn update(opts: Opts, conn: &mut PgConnection) -> QueryResult<()> {
async fn update(opts: Opts, conn: &mut AsyncPgConnection) -> QueryResult<()> {

Check warning on line 26 in src/admin/populate.rs

View check run for this annotation

Codecov / codecov/patch

src/admin/populate.rs#L26

Added line #L26 was not covered by tests
use diesel::dsl::*;

for id in opts.version_ids {
let mut rng = thread_rng();
let mut rng = StdRng::from_entropy();

Check warning on line 30 in src/admin/populate.rs

View check run for this annotation

Codecov / codecov/patch

src/admin/populate.rs#L30

Added line #L30 was not covered by tests
let mut dls = rng.gen_range(5_000i32..10_000);

for day in 0..90 {
Expand All @@ -39,7 +39,8 @@
version_downloads::downloads.eq(dls),
version_downloads::date.eq(date(now - day.days())),
))
.execute(conn)?;
.execute(conn)
.await?;

Check warning on line 43 in src/admin/populate.rs

View check run for this annotation

Codecov / codecov/patch

src/admin/populate.rs#L42-L43

Added lines #L42 - L43 were not covered by tests
}
}
Ok(())
Expand Down