Skip to content

Commit 25d0969

Browse files
committed
PR feedback; improve where clause, improve error message and remove transaction
1 parent a9325dc commit 25d0969

File tree

4 files changed

+26
-34
lines changed

4 files changed

+26
-34
lines changed

database/src/pool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ pub trait Connection: Send + Sync {
201201
/// Update a Try commit to have a `sha` and `parent_sha`. Will update the
202202
/// status of the request too a ready state.
203203
async fn attach_shas_to_try_benchmark_request(
204-
&mut self,
204+
&self,
205205
pr: u32,
206206
sha: &str,
207207
parent_sha: &str,
@@ -548,7 +548,7 @@ mod tests {
548548
async fn updating_try_commits() {
549549
run_postgres_test(|ctx| async {
550550
let db = ctx.db_client();
551-
let mut db = db.connection().await;
551+
let db = db.connection().await;
552552
let time = chrono::DateTime::from_str("2021-09-01T00:00:00.000Z").unwrap();
553553
let pr = 42;
554554

database/src/pool/postgres.rs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,38 +1527,35 @@ where
15271527
}
15281528

15291529
async fn attach_shas_to_try_benchmark_request(
1530-
&mut self,
1530+
&self,
15311531
pr: u32,
15321532
sha: &str,
15331533
parent_sha: &str,
15341534
) -> anyhow::Result<()> {
1535-
let tx = self
1536-
.conn_mut()
1537-
.transaction()
1538-
.await
1539-
.context("failed to start transaction")?;
1540-
1541-
tx.execute(
1542-
"UPDATE
1535+
self.conn()
1536+
.execute(
1537+
"UPDATE
15431538
benchmark_request
15441539
SET
15451540
tag = $1,
15461541
parent_sha = $2,
15471542
status = $3
15481543
WHERE
15491544
pr = $4
1550-
AND commit_type = 'try';",
1551-
&[
1552-
&sha,
1553-
&parent_sha,
1554-
&BenchmarkRequestStatus::ArtifactsReady,
1555-
&(pr as i32),
1556-
],
1557-
)
1558-
.await
1559-
.context("failed to execute UPDATE benchmark_request")?;
1545+
AND commit_type = 'try'
1546+
AND tag IS NULL
1547+
AND status = $5;",
1548+
&[
1549+
&sha,
1550+
&parent_sha,
1551+
&BenchmarkRequestStatus::ArtifactsReady,
1552+
&(pr as i32),
1553+
&BenchmarkRequestStatus::WaitingForArtifacts,
1554+
],
1555+
)
1556+
.await
1557+
.context("failed to execute UPDATE benchmark_request")?;
15601558

1561-
tx.commit().await.context("failed to commit transaction")?;
15621559
Ok(())
15631560
}
15641561
}

database/src/pool/sqlite.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,7 @@ impl Connection for SqliteConnection {
12841284
}
12851285

12861286
async fn attach_shas_to_try_benchmark_request(
1287-
&mut self,
1287+
&self,
12881288
_pr: u32,
12891289
_sha: &str,
12901290
_parent_sha: &str,

site/src/github.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ pub async fn rollup_pr_number(
235235
}
236236

237237
async fn attach_shas_to_try_benchmark_request(
238-
conn: &mut dyn database::pool::Connection,
238+
conn: &dyn database::pool::Connection,
239239
pr: u32,
240240
sha: &str,
241241
parent_sha: &str,
@@ -245,7 +245,7 @@ async fn attach_shas_to_try_benchmark_request(
245245
.attach_shas_to_try_benchmark_request(pr, sha, parent_sha)
246246
.await
247247
{
248-
log::error!("Cron job failed to execute {}", e);
248+
log::error!("Failed to add shas to try commit {}", e);
249249
}
250250
}
251251
}
@@ -274,15 +274,10 @@ pub async fn enqueue_shas(
274274
sha: commit_response.sha,
275275
parent_sha: commit_response.parents.remove(0).sha,
276276
};
277-
let mut conn = ctxt.conn().await;
278-
279-
attach_shas_to_try_benchmark_request(
280-
&mut *conn,
281-
pr_number,
282-
&try_commit.sha,
283-
&try_commit.sha,
284-
)
285-
.await;
277+
let conn = ctxt.conn().await;
278+
279+
attach_shas_to_try_benchmark_request(&*conn, pr_number, &try_commit.sha, &try_commit.sha)
280+
.await;
286281

287282
let queued = conn
288283
.pr_attach_commit(

0 commit comments

Comments
 (0)