Skip to content

Commit

Permalink
without conn
Browse files Browse the repository at this point in the history
  • Loading branch information
syphar committed Sep 22, 2024
1 parent 0a1b698 commit e4a8244
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
20 changes: 5 additions & 15 deletions src/build_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,8 @@ impl BuildQueue {
})
}

pub(crate) async fn has_build_queued(
&self,
conn: &mut sqlx::PgConnection,
name: &str,
version: &str,
) -> Result<bool> {
pub(crate) async fn has_build_queued(&self, name: &str, version: &str) -> Result<bool> {
let mut conn = self.db.get_async().await?;
Ok(sqlx::query_scalar!(
"SELECT id
FROM queue
Expand Down Expand Up @@ -501,7 +497,7 @@ impl BuildQueue {
update_latest_version_id(&mut *conn, crate_id).await?;
} else {
match self
.has_build_queued(&mut *conn, name, version)
.has_build_queued(name, version)
.await
.context("error trying to fetch build queue")
{
Expand Down Expand Up @@ -678,20 +674,14 @@ mod tests {
queue.add_crate("dummy", "0.1.1", 0, None)?;
env.runtime().block_on(async {
let mut conn = env.async_db().await.async_conn().await;
assert!(queue
.has_build_queued(&mut conn, "dummy", "0.1.1")
.await
.unwrap());
assert!(queue.has_build_queued("dummy", "0.1.1").await.unwrap());

sqlx::query!("UPDATE queue SET attempt = 6")
.execute(&mut *conn)
.await
.unwrap();

assert!(!queue
.has_build_queued(&mut conn, "dummy", "0.1.1")
.await
.unwrap());
assert!(!queue.has_build_queued("dummy", "0.1.1").await.unwrap());
});

Ok(())
Expand Down
5 changes: 2 additions & 3 deletions src/web/builds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ async fn build_trigger_check(
}

let crate_version_is_in_queue = build_queue
.has_build_queued(&mut *conn, name, &version.to_string())
.has_build_queued(name, &version.to_string())
.await?;

if crate_version_is_in_queue {
Expand Down Expand Up @@ -268,10 +268,9 @@ mod tests {

fn has_build_queued(env: &TestEnvironment, name: &str, version: &str) -> anyhow::Result<bool> {
env.runtime().block_on(async move {
let mut conn = env.async_db().await.async_conn().await;
let build_queue = env.build_queue();

build_queue.has_build_queued(&mut conn, name, version).await
build_queue.has_build_queued(name, version).await
})
}

Expand Down

0 comments on commit e4a8244

Please sign in to comment.