Skip to content

Commit 9f3fe88

Browse files
committed
move StatisticSeries to database crate
1 parent 284b059 commit 9f3fe88

File tree

3 files changed

+57
-44
lines changed

3 files changed

+57
-44
lines changed

database/src/lib.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ use serde::{Deserialize, Serialize};
66
use std::fmt;
77
use std::hash;
88
use std::ops::{Add, Sub};
9+
use std::sync::Arc;
910
use std::time::Duration;
1011

1112
pub mod pool;
13+
pub mod selector;
1214

1315
pub use pool::{Connection, Pool};
1416

@@ -431,6 +433,34 @@ intern!(pub struct QueryLabel);
431433
#[derive(Serialize, Deserialize, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
432434
pub struct ArtifactIdNumber(pub u32);
433435

436+
#[derive(Debug)]
437+
pub struct ArtifactIdIter {
438+
ids: Arc<Vec<ArtifactId>>,
439+
idx: usize,
440+
}
441+
442+
impl ArtifactIdIter {
443+
pub fn new(artifact_ids: Arc<Vec<ArtifactId>>) -> ArtifactIdIter {
444+
ArtifactIdIter {
445+
ids: artifact_ids,
446+
idx: 0,
447+
}
448+
}
449+
}
450+
451+
impl Iterator for ArtifactIdIter {
452+
type Item = ArtifactId;
453+
fn next(&mut self) -> Option<Self::Item> {
454+
let r = self.ids.get(self.idx)?;
455+
self.idx += 1;
456+
Some(r.clone())
457+
}
458+
459+
fn size_hint(&self) -> (usize, Option<usize>) {
460+
(self.ids.len(), Some(self.ids.len()))
461+
}
462+
}
463+
434464
/// Cached Id lookups for many database tables.
435465
///
436466
/// This is a quick way to find what the database id for something.

database/src/selector.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use crate::{ArtifactId, ArtifactIdIter};
2+
3+
#[derive(Debug)]
4+
pub struct StatisticSeries {
5+
pub artifact_ids: ArtifactIdIter,
6+
pub points: std::vec::IntoIter<Option<f64>>,
7+
}
8+
9+
impl Iterator for StatisticSeries {
10+
type Item = (ArtifactId, Option<f64>);
11+
fn next(&mut self) -> Option<Self::Item> {
12+
Some((self.artifact_ids.next()?, self.points.next().unwrap()))
13+
}
14+
15+
fn size_hint(&self) -> (usize, Option<usize>) {
16+
self.artifact_ids.size_hint()
17+
}
18+
}

site/src/selector.rs

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ use crate::interpolate::Interpolate;
2626
use crate::load::SiteCtxt;
2727

2828
use collector::Bound;
29+
use database::selector::StatisticSeries;
30+
use database::ArtifactIdIter;
2931
use database::{Benchmark, CodegenBackend, Commit, Connection, Index, Lookup};
3032

3133
use crate::comparison::Metric;
@@ -86,34 +88,6 @@ pub fn range_subset(data: Vec<Commit>, range: RangeInclusive<Bound>) -> Vec<Comm
8688
}
8789
}
8890

89-
#[derive(Debug)]
90-
struct ArtifactIdIter {
91-
ids: Arc<Vec<ArtifactId>>,
92-
idx: usize,
93-
}
94-
95-
impl ArtifactIdIter {
96-
fn new(artifact_ids: Arc<Vec<ArtifactId>>) -> ArtifactIdIter {
97-
ArtifactIdIter {
98-
ids: artifact_ids,
99-
idx: 0,
100-
}
101-
}
102-
}
103-
104-
impl Iterator for ArtifactIdIter {
105-
type Item = ArtifactId;
106-
fn next(&mut self) -> Option<Self::Item> {
107-
let r = self.ids.get(self.idx)?;
108-
self.idx += 1;
109-
Some(r.clone())
110-
}
111-
112-
fn size_hint(&self) -> (usize, Option<usize>) {
113-
(self.ids.len(), Some(self.ids.len()))
114-
}
115-
}
116-
11791
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
11892
pub enum Selector<T> {
11993
All,
@@ -425,13 +399,15 @@ impl SiteCtxt {
425399
}
426400
}
427401

428-
#[derive(Debug)]
429-
pub struct StatisticSeries {
430-
artifact_ids: ArtifactIdIter,
431-
points: std::vec::IntoIter<Option<f64>>,
402+
trait StatisticSeriesExt {
403+
async fn execute_query<Q: BenchmarkQuery>(
404+
artifact_ids: Arc<Vec<ArtifactId>>,
405+
ctxt: &SiteCtxt,
406+
query: Q,
407+
) -> Result<Vec<SeriesResponse<Q::TestCase, StatisticSeries>>, String>;
432408
}
433409

434-
impl StatisticSeries {
410+
impl StatisticSeriesExt for StatisticSeries {
435411
async fn execute_query<Q: BenchmarkQuery>(
436412
artifact_ids: Arc<Vec<ArtifactId>>,
437413
ctxt: &SiteCtxt,
@@ -453,14 +429,3 @@ impl StatisticSeries {
453429
Ok(result)
454430
}
455431
}
456-
457-
impl Iterator for StatisticSeries {
458-
type Item = (ArtifactId, Option<f64>);
459-
fn next(&mut self) -> Option<Self::Item> {
460-
Some((self.artifact_ids.next()?, self.points.next().unwrap()))
461-
}
462-
463-
fn size_hint(&self) -> (usize, Option<usize>) {
464-
self.artifact_ids.size_hint()
465-
}
466-
}

0 commit comments

Comments
 (0)