Skip to content

Commit dc9941c

Browse files
Merge pull request #1399 from rust-lang/next-commit-real
Store try commit dates into the DB properly
2 parents 74cc697 + 1119337 commit dc9941c

File tree

10 files changed

+75
-25
lines changed

10 files changed

+75
-25
lines changed

collector/src/api.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
pub mod next_commit {
2+
use database::Commit;
3+
24
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
3-
pub struct Commit {
4-
pub sha: String,
5+
pub struct NextCommit {
6+
pub commit: Commit,
57
pub include: Option<String>,
68
pub exclude: Option<String>,
79
pub runs: Option<i32>,
810
}
911

1012
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
1113
pub struct Response {
12-
pub commit: Option<Commit>,
14+
pub commit: Option<NextCommit>,
1315
}
1416
}

collector/src/main.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,12 +1008,11 @@ fn main_result() -> anyhow::Result<i32> {
10081008
// no missing commits
10091009
return Ok(0);
10101010
};
1011-
let commit = get_commit_or_fake_it(&next.sha)?;
10121011

10131012
let pool = database::Pool::open(&db.db);
10141013

1015-
let sysroot = Sysroot::install(commit.sha.to_string(), &target_triple)
1016-
.with_context(|| format!("failed to install sysroot for {:?}", commit))?;
1014+
let sysroot = Sysroot::install(next.commit.sha.to_string(), &target_triple)
1015+
.with_context(|| format!("failed to install sysroot for {:?}", next.commit))?;
10171016

10181017
let mut benchmarks = get_benchmarks(
10191018
&benchmark_dir,
@@ -1025,7 +1024,7 @@ fn main_result() -> anyhow::Result<i32> {
10251024
let res = bench(
10261025
&mut rt,
10271026
pool,
1028-
&ArtifactId::Commit(commit),
1027+
&ArtifactId::Commit(next.commit),
10291028
&Profile::all(),
10301029
&Scenario::all(),
10311030
bench_rustc.bench_rustc,

database/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub struct QueuedCommit {
2323
pub include: Option<String>,
2424
pub exclude: Option<String>,
2525
pub runs: Option<i32>,
26+
pub commit_date: Option<Date>,
2627
}
2728

2829
#[derive(Debug, Hash, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]

database/src/pool.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,13 @@ pub trait Connection: Send + Sync {
102102
runs: Option<i32>,
103103
);
104104
/// Returns true if this PR was queued waiting for a commit
105-
async fn pr_attach_commit(&self, pr: u32, sha: &str, parent_sha: &str) -> bool;
105+
async fn pr_attach_commit(
106+
&self,
107+
pr: u32,
108+
sha: &str,
109+
parent_sha: &str,
110+
commit_date: Option<DateTime<Utc>>,
111+
) -> bool;
106112
async fn queued_commits(&self) -> Vec<QueuedCommit>;
107113
async fn mark_complete(&self, sha: &str) -> Option<QueuedCommit>;
108114

database/src/pool/postgres.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ static MIGRATIONS: &[&str] = &[
212212
r#"
213213
alter table benchmark add column category text not null DEFAULT 'secondary';
214214
"#,
215+
r#"
216+
alter table pull_request_build add column commit_date timestamptz;
217+
"#,
215218
];
216219

217220
#[async_trait::async_trait]
@@ -623,12 +626,18 @@ where
623626
log::error!("failed to queue_pr({}, {:?}, {:?}, {:?}): {:?}", pr, include, exclude, runs, e);
624627
}
625628
}
626-
async fn pr_attach_commit(&self, pr: u32, sha: &str, parent_sha: &str) -> bool {
629+
async fn pr_attach_commit(
630+
&self,
631+
pr: u32,
632+
sha: &str,
633+
parent_sha: &str,
634+
commit_date: Option<DateTime<Utc>>,
635+
) -> bool {
627636
self.conn()
628637
.execute(
629-
"update pull_request_build SET bors_sha = $1, parent_sha = $2
638+
"update pull_request_build SET bors_sha = $1, parent_sha = $2, commit_date = $4
630639
where pr = $3 and bors_sha is null",
631-
&[&sha, &parent_sha, &(pr as i32)],
640+
&[&sha, &parent_sha, &(pr as i32), &commit_date],
632641
)
633642
.await
634643
.unwrap()
@@ -638,7 +647,7 @@ where
638647
let rows = self
639648
.conn()
640649
.query(
641-
"select pr, bors_sha, parent_sha, include, exclude, runs from pull_request_build
650+
"select pr, bors_sha, parent_sha, include, exclude, runs, commit_date from pull_request_build
642651
where complete is false and bors_sha is not null
643652
order by requested asc",
644653
&[],
@@ -653,6 +662,7 @@ where
653662
include: row.get(3),
654663
exclude: row.get(4),
655664
runs: row.get(5),
665+
commit_date: row.get::<_, Option<_>>(6).map(Date),
656666
})
657667
.collect()
658668
}
@@ -662,7 +672,7 @@ where
662672
.query_opt(
663673
"update pull_request_build SET complete = true
664674
where bors_sha = $1
665-
returning pr, bors_sha, parent_sha, include, exclude, runs",
675+
returning pr, bors_sha, parent_sha, include, exclude, runs, commit_date",
666676
&[&sha],
667677
)
668678
.await
@@ -674,6 +684,7 @@ where
674684
include: row.get(3),
675685
exclude: row.get(4),
676686
runs: row.get(5),
687+
commit_date: row.get::<_, Option<_>>(6).map(Date),
677688
})
678689
}
679690
async fn collection_id(&self, version: &str) -> CollectionId {

database/src/pool/sqlite.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{
33
ArtifactId, Benchmark, BenchmarkData, CollectionId, Commit, CommitType, Date, Profile,
44
};
55
use crate::{ArtifactIdNumber, Index, QueryDatum, QueuedCommit};
6-
use chrono::{DateTime, TimeZone, Utc};
6+
use chrono::{DateTime, NaiveDateTime, TimeZone, Utc};
77
use hashbrown::HashMap;
88
use rusqlite::params;
99
use rusqlite::OptionalExtension;
@@ -321,6 +321,7 @@ static MIGRATIONS: &[Migration] = &[
321321
"#,
322322
),
323323
Migration::new("alter table benchmark add column category text not null default ''"),
324+
Migration::new("alter table pull_request_build add column commit_date timestamp"),
324325
];
325326

326327
#[async_trait::async_trait]
@@ -564,21 +565,28 @@ impl Connection for SqliteConnection {
564565
.execute(params![pr, include, exclude, &runs])
565566
.unwrap();
566567
}
567-
async fn pr_attach_commit(&self, pr: u32, sha: &str, parent_sha: &str) -> bool {
568+
async fn pr_attach_commit(
569+
&self,
570+
pr: u32,
571+
sha: &str,
572+
parent_sha: &str,
573+
commit_date: Option<DateTime<Utc>>,
574+
) -> bool {
575+
let timestamp = commit_date.map(|d| d.timestamp());
568576
self.raw_ref()
569577
.prepare_cached(
570-
"update pull_request_build SET bors_sha = ?, parent_sha = ?
578+
"update pull_request_build SET bors_sha = ?, parent_sha = ?, commit_date = ?
571579
where pr = ? and bors_sha is null",
572580
)
573581
.unwrap()
574-
.execute(params![sha, parent_sha, pr])
582+
.execute(params![sha, parent_sha, timestamp, pr])
575583
.unwrap()
576584
> 0
577585
}
578586
async fn queued_commits(&self) -> Vec<QueuedCommit> {
579587
self.raw_ref()
580588
.prepare_cached(
581-
"select pr, bors_sha, parent_sha, include, exclude, runs from pull_request_build
589+
"select pr, bors_sha, parent_sha, include, exclude, runs, commit_date from pull_request_build
582590
where complete is false and bors_sha is not null
583591
order by requested asc",
584592
)
@@ -593,6 +601,7 @@ impl Connection for SqliteConnection {
593601
include: row.get(3).unwrap(),
594602
exclude: row.get(4).unwrap(),
595603
runs: row.get(5).unwrap(),
604+
commit_date: row.get::<_, Option<i64>>(6).unwrap().map(|timestamp| Date(DateTime::from_utc(NaiveDateTime::from_timestamp(timestamp, 0), Utc)))
596605
})
597606
})
598607
.collect::<Result<Vec<_>, _>>()
@@ -612,7 +621,7 @@ impl Connection for SqliteConnection {
612621
assert_eq!(count, 1, "sha is unique column");
613622
self.raw_ref()
614623
.query_row(
615-
"select pr, sha, parent_sha, include, exclude, runs from pull_request_build
624+
"select pr, sha, parent_sha, include, exclude, runs, commit_date from pull_request_build
616625
where sha = ?",
617626
params![sha],
618627
|row| {
@@ -623,6 +632,7 @@ impl Connection for SqliteConnection {
623632
include: row.get(3).unwrap(),
624633
exclude: row.get(4).unwrap(),
625634
runs: row.get(5).unwrap(),
635+
commit_date: row.get::<_, Option<i64>>(6).unwrap().map(|timestamp| Date(DateTime::from_utc(NaiveDateTime::from_timestamp(timestamp, 0), Utc)))
626636
})
627637
},
628638
)

site/src/github.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,13 @@ pub async fn enqueue_shas(
189189
};
190190
let queued = {
191191
let conn = ctxt.conn().await;
192-
conn.pr_attach_commit(pr_number, &try_commit.sha, &try_commit.parent_sha)
193-
.await
192+
conn.pr_attach_commit(
193+
pr_number,
194+
&try_commit.sha,
195+
&try_commit.parent_sha,
196+
Some(commit_response.commit.committer.date),
197+
)
198+
.await
194199
};
195200
if queued {
196201
if !msg.is_empty() {

site/src/github/client.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use anyhow::Context;
2+
use chrono::{DateTime, Utc};
23
use http::header::USER_AGENT;
34

45
use crate::{api::github::Issue, load::SiteCtxt};
@@ -253,6 +254,12 @@ pub struct InnerCommit {
253254
#[serde(default)]
254255
pub message: String,
255256
pub tree: CommitTree,
257+
pub committer: Committer,
258+
}
259+
260+
#[derive(Debug, Clone, serde::Deserialize)]
261+
pub struct Committer {
262+
pub date: DateTime<Utc>,
256263
}
257264

258265
#[derive(Debug, Clone, serde::Deserialize)]

site/src/load.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ fn calculate_missing_from(
306306
include,
307307
exclude,
308308
runs,
309+
commit_date,
309310
} in queued_pr_commits
310311
.into_iter()
311312
// filter out any queued PR master commits (leaving only try commits)
@@ -322,7 +323,7 @@ fn calculate_missing_from(
322323
queue.push((
323324
Commit {
324325
sha: sha.to_string(),
325-
date: Date::ymd_hms(2001, 01, 01, 0, 0, 0),
326+
date: commit_date.unwrap_or(Date::empty()),
326327
r#type: CommitType::Try,
327328
},
328329
MissingReason::Try {
@@ -499,6 +500,7 @@ mod tests {
499500
include: None,
500501
exclude: None,
501502
runs: None,
503+
commit_date: None,
502504
},
503505
QueuedCommit {
504506
sha: "b".into(),
@@ -507,6 +509,7 @@ mod tests {
507509
include: None,
508510
exclude: None,
509511
runs: None,
512+
commit_date: None,
510513
},
511514
QueuedCommit {
512515
sha: "a".into(),
@@ -515,6 +518,7 @@ mod tests {
515518
include: None,
516519
exclude: None,
517520
runs: None,
521+
commit_date: None,
518522
},
519523
];
520524
let in_progress_artifacts = vec![];
@@ -606,6 +610,7 @@ mod tests {
606610
include: None,
607611
exclude: None,
608612
runs: None,
613+
commit_date: None,
609614
},
610615
// A try run
611616
QueuedCommit {
@@ -615,6 +620,7 @@ mod tests {
615620
include: None,
616621
exclude: None,
617622
runs: None,
623+
commit_date: None,
618624
},
619625
];
620626
let in_progress_artifacts = vec![];

site/src/request_handlers/next_commit.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ pub async fn handle_next_commit(ctxt: Arc<SiteCtxt>) -> next_commit::Response {
1818
// TODO: add capability of doing the following in one step
1919
// to avoid possibile illegal inbetween states.
2020
conn.queue_pr(pr, None, None, None).await;
21-
if !conn.pr_attach_commit(pr, &commit.sha, parent_sha).await {
21+
if !conn
22+
.pr_attach_commit(pr, &commit.sha, parent_sha, None)
23+
.await
24+
{
2225
log::error!("failed to attach commit {} to PR queue", commit.sha);
2326
}
2427
}
@@ -49,8 +52,8 @@ pub async fn handle_next_commit(ctxt: Arc<SiteCtxt>) -> next_commit::Response {
4952
commit.sha,
5053
missing_reason_dbg
5154
);
52-
Some(next_commit::Commit {
53-
sha: commit.sha,
55+
Some(next_commit::NextCommit {
56+
commit,
5457
include,
5558
exclude,
5659
runs,

0 commit comments

Comments
 (0)