Skip to content

Commit 76d75ca

Browse files
committed
Explicitly mark commits as being try or master instead of relying on their date
1 parent a822cbd commit 76d75ca

File tree

8 files changed

+59
-21
lines changed

8 files changed

+59
-21
lines changed

collector/src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use anyhow::{bail, Context};
44
use clap::Parser;
55
use collector::category::Category;
6-
use database::{ArtifactId, Commit};
6+
use database::{ArtifactId, Commit, CommitType};
77
use log::debug;
88
use rayon::iter::{IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator};
99
use std::collections::HashMap;
@@ -1376,12 +1376,14 @@ pub fn get_commit_or_fake_it(sha: &str) -> anyhow::Result<Commit> {
13761376
.map(|c| Commit {
13771377
sha: c.sha.as_str().into(),
13781378
date: c.time.into(),
1379+
r#type: CommitType::Master,
13791380
})
13801381
.unwrap_or_else(|| {
13811382
log::warn!("utilizing fake commit!");
13821383
Commit {
13831384
sha: sha.into(),
13841385
date: database::Date::ymd_hms(2000, 01, 01, 0, 0, 0),
1386+
r#type: CommitType::Master,
13851387
}
13861388
}))
13871389
}

database/src/bin/ingest-json.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -880,11 +880,7 @@ async fn ingest<T: Ingesting>(conn: &T, caches: &mut IdCache, path: &Path) {
880880
let (name, date, ty, benchmarks) = match res {
881881
Res::Commit(cd) => (
882882
cd.commit.sha.to_string(),
883-
if cd.commit.is_try() {
884-
None
885-
} else {
886-
Some(cd.commit.date.0)
887-
},
883+
Some(cd.commit.date.0),
888884
if cd.commit.is_try() { "try" } else { "master" },
889885
cd.benchmarks,
890886
),

database/src/lib.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use chrono::offset::TimeZone;
2-
use chrono::{DateTime, Datelike, NaiveDate, Utc};
2+
use chrono::{DateTime, Datelike, Utc};
33
use hashbrown::HashMap;
44
use intern::intern;
55
use serde::{Deserialize, Serialize};
@@ -148,16 +148,34 @@ impl<'de> Deserialize<'de> for Date {
148148
}
149149
}
150150

151+
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
152+
pub enum CommitType {
153+
Try,
154+
Master,
155+
}
156+
157+
impl FromStr for CommitType {
158+
type Err = String;
159+
160+
fn from_str(ty: &str) -> Result<Self, Self::Err> {
161+
match ty {
162+
"try" => Ok(CommitType::Try),
163+
"master" => Ok(CommitType::Master),
164+
_ => Err(format!("Wrong commit type {}", ty)),
165+
}
166+
}
167+
}
168+
151169
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
152170
pub struct Commit {
153171
pub sha: String,
154172
pub date: Date,
173+
pub r#type: CommitType,
155174
}
156175

157176
impl Commit {
158177
pub fn is_try(&self) -> bool {
159-
self.date.0.naive_utc().date() == NaiveDate::from_ymd(2000, 1, 1)
160-
|| self.date.0.naive_utc().date() == NaiveDate::from_ymd(2001, 1, 1)
178+
matches!(self.r#type, CommitType::Try)
161179
}
162180
}
163181

@@ -298,6 +316,7 @@ impl Scenario {
298316
}
299317

300318
use std::cmp::Ordering;
319+
use std::str::FromStr;
301320

302321
// We sort println before all other patches.
303322
impl Ord for Scenario {

database/src/pool/postgres.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
use crate::pool::{Connection, ConnectionManager, ManagedConnection, Transaction};
22
use crate::{
3-
ArtifactId, ArtifactIdNumber, Benchmark, BenchmarkData, CollectionId, Commit, Date, Index,
4-
Profile, QueuedCommit, Scenario,
3+
ArtifactId, ArtifactIdNumber, Benchmark, BenchmarkData, CollectionId, Commit, CommitType, Date,
4+
Index, Profile, QueuedCommit, Scenario,
55
};
66
use anyhow::Context as _;
77
use chrono::{DateTime, TimeZone, Utc};
88
use hashbrown::HashMap;
99
use native_tls::{Certificate, TlsConnector};
1010
use postgres_native_tls::MakeTlsConnector;
1111
use std::convert::TryFrom;
12+
use std::str::FromStr;
1213
use std::sync::Arc;
1314
use std::time::Duration;
1415
use tokio_postgres::GenericClient;
@@ -502,7 +503,7 @@ where
502503
commits: self
503504
.conn()
504505
.query(
505-
"select id, name, date from artifact where type = 'master' or type = 'try'",
506+
"select id, name, date, type from artifact where type = 'master' or type = 'try'",
506507
&[],
507508
)
508509
.await
@@ -520,6 +521,7 @@ where
520521
None => Date(Utc.ymd(2001, 01, 01).and_hms(0, 0, 0)),
521522
}
522523
},
524+
r#type: CommitType::from_str(&row.get::<_, String>(3)).unwrap()
523525
},
524526
)
525527
})
@@ -1117,6 +1119,7 @@ where
11171119
.get::<_, Option<_>>(1)
11181120
.map(Date)
11191121
.unwrap_or_else(|| Date::ymd_hms(2001, 01, 01, 0, 0, 0)),
1122+
r#type: CommitType::from_str(&ty).unwrap(),
11201123
}),
11211124
"release" => ArtifactId::Tag(row.get(0)),
11221125
_ => {
@@ -1306,10 +1309,12 @@ where
13061309
"master" => Some(ArtifactId::Commit(Commit {
13071310
sha: artifact.to_owned(),
13081311
date: Date(date.expect("date present for master commits")),
1312+
r#type: CommitType::Master,
13091313
})),
13101314
"try" => Some(ArtifactId::Commit(Commit {
13111315
sha: artifact.to_owned(),
13121316
date: Date::ymd_hms(2000, 1, 1, 0, 0, 0),
1317+
r#type: CommitType::Try,
13131318
})),
13141319
"release" => Some(ArtifactId::Tag(artifact.to_owned())),
13151320
_ => panic!("unknown artifact type: {:?}", ty),

database/src/pool/sqlite.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
use crate::pool::{Connection, ConnectionManager, ManagedConnection, Transaction};
2-
use crate::{ArtifactId, Benchmark, BenchmarkData, CollectionId, Commit, Date, Profile};
2+
use crate::{
3+
ArtifactId, Benchmark, BenchmarkData, CollectionId, Commit, CommitType, Date, Profile,
4+
};
35
use crate::{ArtifactIdNumber, Index, QueryDatum, QueuedCommit};
46
use chrono::{DateTime, TimeZone, Utc};
57
use hashbrown::HashMap;
68
use rusqlite::params;
79
use rusqlite::OptionalExtension;
810
use std::convert::TryFrom;
911
use std::path::PathBuf;
12+
use std::str::FromStr;
1013
use std::sync::Mutex;
1114
use std::sync::Once;
1215
use std::time::Duration;
@@ -402,7 +405,9 @@ impl Connection for SqliteConnection {
402405
async fn load_index(&mut self) -> Index {
403406
let commits = self
404407
.raw()
405-
.prepare("select id, name, date from artifact where type = 'master' or type = 'try'")
408+
.prepare(
409+
"select id, name, date, type from artifact where type = 'master' or type = 'try'",
410+
)
406411
.unwrap()
407412
.query_map(params![], |row| {
408413
Ok((
@@ -416,6 +421,7 @@ impl Connection for SqliteConnection {
416421
None => Date(Utc.ymd(2001, 01, 01).and_hms(0, 0, 0)),
417422
}
418423
},
424+
r#type: CommitType::from_str(&row.get::<_, String>(3)?).unwrap(),
419425
},
420426
))
421427
})
@@ -785,11 +791,7 @@ impl Connection for SqliteConnection {
785791
let (name, date, ty) = match artifact {
786792
crate::ArtifactId::Commit(commit) => (
787793
commit.sha.to_string(),
788-
if commit.is_try() {
789-
None
790-
} else {
791-
Some(commit.date.0)
792-
},
794+
Some(commit.date.0),
793795
if commit.is_try() { "try" } else { "master" },
794796
),
795797
crate::ArtifactId::Tag(a) => (a.clone(), None, "release"),
@@ -983,6 +985,7 @@ impl Connection for SqliteConnection {
983985
.map(|d| Utc.timestamp(d, 0))
984986
.map(Date)
985987
.unwrap_or_else(|| Date::ymd_hms(2001, 01, 01, 0, 0, 0)),
988+
r#type: CommitType::from_str(&ty).unwrap(),
986989
}),
987990
"release" => ArtifactId::Tag(name),
988991
_ => {
@@ -1180,10 +1183,12 @@ impl Connection for SqliteConnection {
11801183
"master" => Some(ArtifactId::Commit(Commit {
11811184
sha: artifact.to_owned(),
11821185
date: Date(Utc.timestamp(date.expect("master has date"), 0)),
1186+
r#type: CommitType::Master,
11831187
})),
11841188
"try" => Some(ArtifactId::Commit(Commit {
11851189
sha: artifact.to_owned(),
11861190
date: Date::ymd_hms(2000, 1, 1, 0, 0, 0),
1191+
r#type: CommitType::Try,
11871192
})),
11881193
"release" => Some(ArtifactId::Tag(artifact.to_owned())),
11891194
_ => panic!("unknown artifact type: {:?}", ty),

site/src/comparison.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use collector::category::Category;
1212
use collector::Bound;
1313
use serde::{Deserialize, Serialize};
1414

15+
use database::CommitType;
1516
use std::cmp::Ordering;
1617
use std::collections::{HashMap, HashSet};
1718
use std::error::Error;
@@ -720,6 +721,7 @@ fn previous_commits(
720721
let new = ArtifactId::Commit(database::Commit {
721722
sha: c.sha.clone(),
722723
date: database::Date(c.time),
724+
r#type: CommitType::Master,
723725
});
724726
from = new.clone();
725727
prevs.push(new);

site/src/load.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ use serde::{Deserialize, Serialize};
1313
use crate::api::github;
1414
use crate::db;
1515
use collector::{category::Category, Bound, MasterCommit};
16-
use database::Date;
1716
use database::Pool;
1817
pub use database::{ArtifactId, Benchmark, Commit};
18+
use database::{CommitType, Date};
1919

2020
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
2121
pub enum MissingReason {
@@ -286,6 +286,7 @@ fn calculate_missing_from(
286286
Commit {
287287
sha: c.sha,
288288
date: Date(c.time),
289+
r#type: CommitType::Master,
289290
},
290291
// All recent master commits should have an associated PR
291292
MissingReason::Master {
@@ -324,6 +325,7 @@ fn calculate_missing_from(
324325
Commit {
325326
sha: sha.to_string(),
326327
date: Date::ymd_hms(2001, 01, 01, 0, 0, 0),
328+
r#type: CommitType::Try,
327329
},
328330
MissingReason::Try {
329331
pr,
@@ -526,6 +528,7 @@ mod tests {
526528
Commit {
527529
sha: "b".into(),
528530
date: database::Date(time),
531+
r#type: CommitType::Master,
529532
},
530533
MissingReason::Master {
531534
pr: 1,
@@ -537,6 +540,7 @@ mod tests {
537540
Commit {
538541
sha: "a".into(),
539542
date: database::Date(time),
543+
r#type: CommitType::Master,
540544
},
541545
MissingReason::Master {
542546
pr: 2,
@@ -548,6 +552,7 @@ mod tests {
548552
Commit {
549553
sha: "try-on-a".into(),
550554
date: database::Date(time),
555+
r#type: CommitType::Try,
551556
},
552557
MissingReason::Try {
553558
pr: 3,
@@ -627,6 +632,7 @@ mod tests {
627632
Commit {
628633
sha: "123".into(),
629634
date: database::Date(time),
635+
r#type: CommitType::Master,
630636
},
631637
MissingReason::Master {
632638
pr: 11,
@@ -638,6 +644,7 @@ mod tests {
638644
Commit {
639645
sha: "foo".into(),
640646
date: database::Date(time),
647+
r#type: CommitType::Master,
641648
},
642649
MissingReason::Master {
643650
pr: 77,
@@ -649,6 +656,7 @@ mod tests {
649656
Commit {
650657
sha: "baz".into(),
651658
date: database::Date(time),
659+
r#type: CommitType::Try,
652660
},
653661
MissingReason::Try {
654662
pr: 101,

site/src/request_handlers/self_profile.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::time::{Duration, Instant};
55

66
use analyzeme::ProfilingData;
77
use bytes::Buf;
8-
use database::{ArtifactIdNumber, Scenario};
8+
use database::{ArtifactIdNumber, CommitType, Scenario};
99
use headers::{ContentType, Header};
1010
use hyper::StatusCode;
1111

@@ -530,6 +530,7 @@ pub async fn handle_self_profile_raw(
530530
ArtifactId::Commit(database::Commit {
531531
sha: body.commit.clone(),
532532
date: database::Date::empty(),
533+
r#type: CommitType::Master,
533534
}),
534535
bench_name,
535536
profile,

0 commit comments

Comments
 (0)