Skip to content

Commit 95f3c81

Browse files
committed
move Bound to database crate
1 parent 284b059 commit 95f3c81

File tree

9 files changed

+112
-108
lines changed

9 files changed

+112
-108
lines changed

collector/src/lib.rs

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
use chrono::NaiveDate;
21
pub use database::{Commit, PatchName, QueryLabel};
32
use serde::Deserialize;
43
use std::cmp::PartialOrd;
5-
use std::fmt;
64
use std::process::{self, Command};
75

86
pub mod api;
@@ -23,94 +21,6 @@ use std::time::{Duration, Instant};
2321
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Deserialize)]
2422
pub struct DeltaTime(#[serde(with = "round_float")] pub f64);
2523

26-
/// The bound for finding an artifact
27-
///
28-
/// This can either be the upper or lower bound.
29-
/// In the case of commits or tags this is an exact bound, but for dates
30-
/// it's a best effort (i.e., if the bound is a date but there are no artifacts
31-
/// for that date, we'll find the artifact that most closely matches).
32-
#[derive(Default, Debug, Clone, PartialEq, Eq)]
33-
pub enum Bound {
34-
/// An unverified git commit (in sha form) or a tag of a commit (e.g., "1.53.0")
35-
Commit(String),
36-
/// A date in time
37-
Date(NaiveDate),
38-
/// No bound
39-
#[default]
40-
None,
41-
}
42-
43-
impl Bound {
44-
/// Tests whether `self` matches commit when searching from the left
45-
pub fn left_match(&self, commit: &Commit) -> bool {
46-
match self {
47-
Bound::Commit(sha) => commit.sha == **sha,
48-
Bound::Date(date) => commit.is_master() && commit.date.0.naive_utc().date() >= *date,
49-
Bound::None => {
50-
let last_month = chrono::Utc::now().date_naive() - chrono::Duration::days(30);
51-
commit.is_master() && last_month <= commit.date.0.naive_utc().date()
52-
}
53-
}
54-
}
55-
56-
/// Tests whether `self` matches commit when searching from the right
57-
pub fn right_match(&self, commit: &Commit) -> bool {
58-
match self {
59-
Bound::Commit(sha) => commit.sha == **sha,
60-
Bound::Date(date) => commit.is_master() && commit.date.0.date_naive() <= *date,
61-
Bound::None => commit.is_master(),
62-
}
63-
}
64-
}
65-
66-
impl serde::Serialize for Bound {
67-
fn serialize<S>(&self, serializer: S) -> ::std::result::Result<S::Ok, S::Error>
68-
where
69-
S: serde::ser::Serializer,
70-
{
71-
let s = match *self {
72-
Bound::Commit(ref s) => s.clone(),
73-
Bound::Date(ref date) => date.format("%Y-%m-%d").to_string(),
74-
Bound::None => String::new(),
75-
};
76-
serializer.serialize_str(&s)
77-
}
78-
}
79-
80-
impl<'de> Deserialize<'de> for Bound {
81-
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Bound, D::Error>
82-
where
83-
D: serde::de::Deserializer<'de>,
84-
{
85-
struct BoundVisitor;
86-
87-
impl<'de> serde::de::Visitor<'de> for BoundVisitor {
88-
type Value = Bound;
89-
90-
fn visit_str<E>(self, value: &str) -> ::std::result::Result<Bound, E>
91-
where
92-
E: serde::de::Error,
93-
{
94-
if value.is_empty() {
95-
return Ok(Bound::None);
96-
}
97-
98-
let bound = value
99-
.parse::<chrono::NaiveDate>()
100-
.map(Bound::Date)
101-
.unwrap_or(Bound::Commit(value.to_string()));
102-
Ok(bound)
103-
}
104-
105-
fn expecting(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
106-
f.write_str("either a YYYY-mm-dd date or a collection ID (usually commit hash)")
107-
}
108-
}
109-
110-
deserializer.deserialize_str(BoundVisitor)
111-
}
112-
}
113-
11424
pub fn null_means_nan<'de, D>(deserializer: D) -> ::std::result::Result<f64, D::Error>
11525
where
11626
D: serde::de::Deserializer<'de>,

database/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::ops::{Add, Sub};
99
use std::time::Duration;
1010

1111
pub mod pool;
12+
pub mod selector;
1213

1314
pub use pool::{Connection, Pool};
1415

database/src/selector.rs

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
use std::fmt;
2+
3+
use chrono::NaiveDate;
4+
use serde::Deserialize;
5+
6+
use crate::Commit;
7+
8+
/// The bound for finding an artifact
9+
///
10+
/// This can either be the upper or lower bound.
11+
/// In the case of commits or tags this is an exact bound, but for dates
12+
/// it's a best effort (i.e., if the bound is a date but there are no artifacts
13+
/// for that date, we'll find the artifact that most closely matches).
14+
#[derive(Default, Debug, Clone, PartialEq, Eq)]
15+
pub enum Bound {
16+
/// An unverified git commit (in sha form) or a tag of a commit (e.g., "1.53.0")
17+
Commit(String),
18+
/// A date in time
19+
Date(NaiveDate),
20+
/// No bound
21+
#[default]
22+
None,
23+
}
24+
25+
impl Bound {
26+
/// Tests whether `self` matches commit when searching from the left
27+
pub fn left_match(&self, commit: &Commit) -> bool {
28+
match self {
29+
Bound::Commit(sha) => commit.sha == **sha,
30+
Bound::Date(date) => commit.is_master() && commit.date.0.naive_utc().date() >= *date,
31+
Bound::None => {
32+
let last_month = chrono::Utc::now().date_naive() - chrono::Duration::days(30);
33+
commit.is_master() && last_month <= commit.date.0.naive_utc().date()
34+
}
35+
}
36+
}
37+
38+
/// Tests whether `self` matches commit when searching from the right
39+
pub fn right_match(&self, commit: &Commit) -> bool {
40+
match self {
41+
Bound::Commit(sha) => commit.sha == **sha,
42+
Bound::Date(date) => commit.is_master() && commit.date.0.date_naive() <= *date,
43+
Bound::None => commit.is_master(),
44+
}
45+
}
46+
}
47+
48+
impl serde::Serialize for Bound {
49+
fn serialize<S>(&self, serializer: S) -> ::std::result::Result<S::Ok, S::Error>
50+
where
51+
S: serde::ser::Serializer,
52+
{
53+
let s = match *self {
54+
Bound::Commit(ref s) => s.clone(),
55+
Bound::Date(ref date) => date.format("%Y-%m-%d").to_string(),
56+
Bound::None => String::new(),
57+
};
58+
serializer.serialize_str(&s)
59+
}
60+
}
61+
62+
impl<'de> Deserialize<'de> for Bound {
63+
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Bound, D::Error>
64+
where
65+
D: serde::de::Deserializer<'de>,
66+
{
67+
struct BoundVisitor;
68+
69+
impl<'de> serde::de::Visitor<'de> for BoundVisitor {
70+
type Value = Bound;
71+
72+
fn visit_str<E>(self, value: &str) -> ::std::result::Result<Bound, E>
73+
where
74+
E: serde::de::Error,
75+
{
76+
if value.is_empty() {
77+
return Ok(Bound::None);
78+
}
79+
80+
let bound = value
81+
.parse::<chrono::NaiveDate>()
82+
.map(Bound::Date)
83+
.unwrap_or(Bound::Commit(value.to_string()));
84+
Ok(bound)
85+
}
86+
87+
fn expecting(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
88+
f.write_str("either a YYYY-mm-dd date or a collection ID (usually commit hash)")
89+
}
90+
}
91+
92+
deserializer.deserialize_str(BoundVisitor)
93+
}
94+
}

site/src/api.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub mod dashboard {
8181

8282
pub mod graph {
8383
use super::graphs::{GraphKind, Series};
84-
use collector::Bound;
84+
use database::selector::Bound;
8585
use serde::{Deserialize, Serialize};
8686

8787
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
@@ -102,7 +102,7 @@ pub mod graph {
102102
}
103103

104104
pub mod graphs {
105-
use collector::Bound;
105+
use database::selector::Bound;
106106
use serde::{Deserialize, Serialize};
107107
use std::collections::{HashMap, HashSet};
108108

@@ -147,7 +147,7 @@ pub mod graphs {
147147
pub mod detail_graphs {
148148
use crate::api::graphs::{GraphKind, Series};
149149
use crate::api::vec_from_comma_separated;
150-
use collector::Bound;
150+
use database::selector::Bound;
151151
use serde::{Deserialize, Serialize};
152152

153153
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
@@ -170,7 +170,7 @@ pub mod detail_graphs {
170170
}
171171

172172
pub mod detail_sections {
173-
use collector::Bound;
173+
use database::selector::Bound;
174174
use serde::{Deserialize, Serialize};
175175

176176
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
@@ -207,7 +207,7 @@ pub mod detail_sections {
207207
pub mod runtime_detail_graphs {
208208
use crate::api::graphs::{GraphKind, Series};
209209
use crate::api::vec_from_comma_separated;
210-
use collector::Bound;
210+
use database::selector::Bound;
211211
use serde::{Deserialize, Serialize};
212212

213213
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
@@ -228,7 +228,7 @@ pub mod runtime_detail_graphs {
228228
}
229229

230230
pub mod bootstrap {
231-
use collector::Bound;
231+
use database::selector::Bound;
232232
use hashbrown::HashMap;
233233
use serde::{Deserialize, Serialize};
234234

@@ -253,8 +253,7 @@ pub mod bootstrap {
253253
pub mod comparison {
254254
use crate::benchmark_metadata::ProfileMetadata;
255255
use crate::comparison::Metric;
256-
use collector::Bound;
257-
use database::Date;
256+
use database::{selector::Bound, Date};
258257
use serde::{Deserialize, Serialize};
259258
use std::collections::HashMap;
260259

@@ -596,7 +595,7 @@ pub mod github {
596595

597596
pub mod triage {
598597
use crate::comparison::Metric;
599-
use collector::Bound;
598+
use database::selector::Bound;
600599
use serde::{Deserialize, Serialize};
601600

602601
#[derive(Debug, Clone, Serialize, Deserialize)]

site/src/comparison.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@ use crate::selector::{
1111
};
1212

1313
use collector::compile::benchmark::category::Category;
14-
use collector::Bound;
1514
use serde::{Deserialize, Serialize};
1615

1716
use crate::api::comparison::CompileBenchmarkMetadata;
1817
use crate::benchmark_metadata::get_compile_benchmarks_metadata;
1918
use crate::server::comparison::StatComparison;
2019
use collector::compile::benchmark::ArtifactType;
21-
use database::{CodegenBackend, CommitType, CompileBenchmark};
20+
use database::{selector::Bound, CodegenBackend, CommitType, CompileBenchmark};
2221
use serde::de::IntoDeserializer;
2322
use std::cmp;
2423
use std::collections::{HashMap, HashSet};

site/src/github/comparison_summary.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::comparison::{
44
};
55
use crate::load::SiteCtxt;
66

7+
use database::selector::Bound;
78
use database::{ArtifactId, QueuedCommit};
89

910
use crate::github::{COMMENT_MARK_ROLLUP, COMMENT_MARK_TEMPORARY, RUST_REPO_GITHUB_API_URL};
@@ -132,8 +133,8 @@ async fn calculate_metric_comparison(
132133
metric: Metric,
133134
) -> Result<ArtifactComparison, String> {
134135
match crate::comparison::compare(
135-
collector::Bound::Commit(commit.parent_sha.clone()),
136-
collector::Bound::Commit(commit.sha.clone()),
136+
Bound::Commit(commit.parent_sha.clone()),
137+
Bound::Commit(commit.sha.clone()),
137138
metric,
138139
ctxt,
139140
)

site/src/load.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::time::Instant;
66

77
use arc_swap::{ArcSwap, Guard};
88
use chrono::{Duration, Utc};
9+
use database::selector::Bound;
910
use lazy_static::lazy_static;
1011
use log::error;
1112
use parking_lot::Mutex;
@@ -15,7 +16,7 @@ use serde::{Deserialize, Serialize};
1516
use crate::db;
1617
use crate::self_profile::SelfProfileCache;
1718
use collector::compile::benchmark::category::Category;
18-
use collector::{Bound, MasterCommit};
19+
use collector::MasterCommit;
1920
use database::Pool;
2021
pub use database::{ArtifactId, Benchmark, Commit};
2122
use database::{CommitType, Date};

site/src/request_handlers/graph.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use std::collections::HashMap;
22
use std::sync::Arc;
33

4-
use collector::Bound;
5-
64
use crate::api::detail_sections::CompilationSections;
75
use crate::api::graphs::GraphKind;
86
use crate::api::{detail_graphs, detail_sections, graphs, runtime_detail_graphs, ServerResult};
@@ -14,6 +12,8 @@ use crate::selector::{
1412
};
1513
use crate::self_profile::get_or_download_self_profile;
1614

15+
use database::selector::Bound;
16+
1717
/// Returns data for before/after graphs when comparing a single test result comparison
1818
/// for a compile-time benchmark.
1919
pub async fn handle_compile_detail_graphs(

site/src/selector.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ use crate::db::{ArtifactId, Profile, Scenario};
2525
use crate::interpolate::Interpolate;
2626
use crate::load::SiteCtxt;
2727

28-
use collector::Bound;
29-
use database::{Benchmark, CodegenBackend, Commit, Connection, Index, Lookup};
28+
use database::{selector::Bound, Benchmark, CodegenBackend, Commit, Connection, Index, Lookup};
3029

3130
use crate::comparison::Metric;
3231
use async_trait::async_trait;

0 commit comments

Comments
 (0)