Skip to content

Commit b3a37f3

Browse files
committed
Pr Feedback; more usage of &str and Option<String> for Try commit parent_sha
1 parent c14d355 commit b3a37f3

File tree

4 files changed

+38
-39
lines changed

4 files changed

+38
-39
lines changed

database/src/lib.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ pub enum BenchmarkRequestType {
843843
/// A Try commit
844844
Try {
845845
sha: String,
846-
parent_sha: String,
846+
parent_sha: Option<String>,
847847
pr: u32,
848848
},
849849
/// A Master commit
@@ -916,7 +916,7 @@ impl BenchmarkRequest {
916916

917917
pub fn create_try(
918918
sha: &str,
919-
parent_sha: &str,
919+
parent_sha: Option<&str>,
920920
pr: u32,
921921
created_at: DateTime<Utc>,
922922
status: BenchmarkRequestStatus,
@@ -927,7 +927,7 @@ impl BenchmarkRequest {
927927
commit_type: BenchmarkRequestType::Try {
928928
pr,
929929
sha: sha.to_string(),
930-
parent_sha: parent_sha.to_string(),
930+
parent_sha: parent_sha.map(|it| it.to_string()),
931931
},
932932
created_at,
933933
completed_at: None,
@@ -984,8 +984,11 @@ impl BenchmarkRequest {
984984

985985
pub fn parent_sha(&self) -> Option<&str> {
986986
match &self.commit_type {
987-
BenchmarkRequestType::Try { parent_sha, .. }
988-
| BenchmarkRequestType::Master { parent_sha, .. } => Some(parent_sha),
987+
BenchmarkRequestType::Try { parent_sha, .. } => match parent_sha {
988+
Some(parent_sha) => Some(parent_sha),
989+
_ => None,
990+
},
991+
BenchmarkRequestType::Master { parent_sha, .. } => Some(parent_sha),
989992
BenchmarkRequestType::Release { tag: _ } => None,
990993
}
991994
}

database/src/pool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ mod tests {
410410

411411
let try_benchmark_request = BenchmarkRequest::create_try(
412412
"b-sha-2",
413-
"parent-sha-2",
413+
Some("parent-sha-2"),
414414
32,
415415
time,
416416
BenchmarkRequestStatus::ArtifactsReady,
@@ -458,7 +458,7 @@ mod tests {
458458

459459
let try_benchmark_request = BenchmarkRequest::create_try(
460460
"b-sha-2",
461-
"parent-sha-2",
461+
Some("parent-sha-2"),
462462
32,
463463
time,
464464
BenchmarkRequestStatus::Completed,

database/src/pool/postgres.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,8 +1432,7 @@ where
14321432
backends,
14331433
profiles
14341434
FROM benchmark_request
1435-
WHERE status = ANY($1)
1436-
AND (commit_type <> 'try' OR parent_sha IS NOT NULL) "
1435+
WHERE status = ANY($1)"
14371436
.to_string();
14381437

14391438
let rows = self
@@ -1446,45 +1445,45 @@ where
14461445
.iter()
14471446
.map(|row| {
14481447
let tag = row.get::<_, &str>(0);
1449-
let parent_sha = row.get::<_, Option<String>>(1);
1448+
let parent_sha = row.get::<_, Option<&str>>(1);
14501449
let pr = row.get::<_, Option<i32>>(2);
1451-
let commit_type = row.get::<_, String>(3);
1450+
let commit_type = row.get::<_, &str>(3);
14521451
let status = row.get::<_, BenchmarkRequestStatus>(4);
14531452
let created_at = row.get::<_, DateTime<Utc>>(5);
14541453
let completed_at = row.get::<_, Option<DateTime<Utc>>>(6);
1455-
let backends = row.get::<_, String>(7);
1456-
let profiles = row.get::<_, String>(8);
1454+
let backends = row.get::<_, &str>(7);
1455+
let profiles = row.get::<_, &str>(8);
14571456

1458-
match commit_type.as_str() {
1457+
match commit_type {
14591458
"try" => {
14601459
let mut try_benchmark = BenchmarkRequest::create_try(
14611460
tag,
1462-
&parent_sha.unwrap(),
1461+
parent_sha,
14631462
pr.unwrap() as u32,
14641463
created_at,
14651464
status,
1466-
&backends,
1467-
&profiles,
1465+
backends,
1466+
profiles,
14681467
);
14691468
try_benchmark.completed_at = completed_at;
14701469
try_benchmark
14711470
}
14721471
"master" => {
14731472
let mut master_benchmark = BenchmarkRequest::create_master(
14741473
tag,
1475-
&parent_sha.unwrap(),
1474+
parent_sha.unwrap(),
14761475
pr.unwrap() as u32,
14771476
created_at,
14781477
status,
1479-
&backends,
1480-
&profiles,
1478+
backends,
1479+
profiles,
14811480
);
14821481
master_benchmark.completed_at = completed_at;
14831482
master_benchmark
14841483
}
14851484
"release" => {
14861485
let mut release_benchmark = BenchmarkRequest::create_release(
1487-
tag, created_at, status, &backends, &profiles,
1486+
tag, created_at, status, backends, profiles,
14881487
);
14891488
release_benchmark.completed_at = completed_at;
14901489
release_benchmark

site/src/job_queue.rs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ async fn create_benchmark_request_master_commits(
3939
/// Sorts try and master requests that are in the `ArtifactsReady` status.
4040
/// Doesn't consider in-progress requests or release artifacts.
4141
fn sort_benchmark_requests(done: &HashSet<String>, request_queue: &mut [BenchmarkRequest]) {
42-
// A topological sort, where each "level" is additionally altered such that
43-
// try commits come first, and then sorted by PR # (as a rough heuristic for
44-
// earlier requests).
4542
let mut done: HashSet<String> = done.iter().cloned().collect();
4643

4744
// Ensure all the items are ready to be sorted, if they are not this is
@@ -256,7 +253,7 @@ mod tests {
256253
fn create_try(sha: &str, parent: &str, pr: u32, age_days: &str) -> BenchmarkRequest {
257254
BenchmarkRequest::create_try(
258255
sha,
259-
parent,
256+
Some(parent),
260257
pr,
261258
days_ago(age_days),
262259
BenchmarkRequestStatus::ArtifactsReady,
@@ -366,18 +363,18 @@ mod tests {
366363
.await;
367364
}
368365

369-
/// Parent exists but is > 30 d old -> parent gets picked
366+
/// Parent exists but is older -> parent gets picked
370367
#[tokio::test]
371368
async fn get_next_benchmark_request_oldest_first() {
372369
run_postgres_test(|ctx| async {
373370
let mut db = ctx.db_client().connection().await;
374371
let c1 = create_master("x", "x", 1, "days521")
375372
.with_status(BenchmarkRequestStatus::Completed);
376-
let c2 = create_master("y", "y", 1, "days521")
373+
let c2 = create_master("y", "y", 2, "days521")
377374
.with_status(BenchmarkRequestStatus::Completed);
378375

379-
let m1 = create_master("old", "x", 2, "days45");
380-
let m2 = create_master("new", "y", 3, "days1");
376+
let m1 = create_master("old", "x", 3, "days45");
377+
let m2 = create_master("new", "y", 4, "days1");
381378

382379
db_insert_requests(&*db, &[c1, c2, m1, m2]).await;
383380
enqueue_next_job(&mut *db).await?;
@@ -415,13 +412,13 @@ mod tests {
415412
run_postgres_test(|ctx| async {
416413
let mut db = ctx.db_client().connection().await;
417414
// Fresh parents that will unblock some children
418-
let parent_master = create_master("parent_m", "x", 999, "days5")
415+
let parent_master = create_master("parent_m", "x", 911, "days5")
419416
.with_status(BenchmarkRequestStatus::Completed);
420417
let parent_try = create_try("parent_t", "x", 888, "days4")
421418
.with_status(BenchmarkRequestStatus::Completed);
422-
let parent_master_two = create_master("gp", "x", 999, "days5")
419+
let parent_master_two = create_master("gp", "x", 922, "days5")
423420
.with_status(BenchmarkRequestStatus::Completed);
424-
let parent_master_three = create_master("blocked_p", "x", 999, "days5")
421+
let parent_master_three = create_master("blocked_p", "x", 932, "days5")
425422
.with_status(BenchmarkRequestStatus::Completed);
426423

427424
// Two releases, the older one should win overall
@@ -468,21 +465,21 @@ mod tests {
468465
run_postgres_test(|ctx| async {
469466
let mut db = ctx.db_client().connection().await;
470467
// Fresh parents that will unblock some children
471-
let parent_master = create_master("parent_m", "x", 999, "days5")
468+
let parent_master = create_master("parent_m", "x", 8, "days5")
472469
.with_status(BenchmarkRequestStatus::Completed);
473-
let parent_try = create_try("parent_t", "x", 888, "days4")
470+
let parent_try = create_try("parent_t", "x", 9, "days4")
474471
.with_status(BenchmarkRequestStatus::Completed);
475-
let parent_master_two = create_master("gp", "x", 999, "days5")
472+
let parent_master_two = create_master("gp", "x", 10, "days5")
476473
.with_status(BenchmarkRequestStatus::Completed);
477-
let parent_master_three = create_master("blocked_p", "x", 999, "days5")
474+
let parent_master_three = create_master("blocked_p", "x", 11, "days5")
478475
.with_status(BenchmarkRequestStatus::Completed);
479476

480477
// Ready masters (parents completed)
481-
let m1 = create_master("m_low", "parent_m", 1, "days12");
478+
let m1 = create_master("m_low", "parent_m", 3, "days12");
482479
let m2 = create_master("m_high", "parent_m", 7, "days8");
483480

484-
let m3 = create_master("B", "gp", 0, "days3");
485-
let m4 = create_master("C", "blocked_p", 0, "days1");
481+
let m3 = create_master("B", "gp", 1, "days3");
482+
let m4 = create_master("C", "blocked_p", 2, "days1");
486483

487484
// A try commit that is ready
488485
let t1 = create_try("t_ready", "parent_t", 42, "days2");

0 commit comments

Comments
 (0)