Skip to content

Commit c4da012

Browse files
committed
move StatisticSeries to database crate
1 parent 95f3c81 commit c4da012

File tree

3 files changed

+56
-45
lines changed

3 files changed

+56
-45
lines changed

database/src/lib.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ 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;
@@ -432,6 +433,34 @@ intern!(pub struct QueryLabel);
432433
#[derive(Serialize, Deserialize, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
433434
pub struct ArtifactIdNumber(pub u32);
434435

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+
435464
/// Cached Id lookups for many database tables.
436465
///
437466
/// This is a quick way to find what the database id for something.

database/src/selector.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::fmt;
33
use chrono::NaiveDate;
44
use serde::Deserialize;
55

6-
use crate::Commit;
6+
use crate::{ArtifactId, ArtifactIdIter, Commit};
77

88
/// The bound for finding an artifact
99
///
@@ -92,3 +92,20 @@ impl<'de> Deserialize<'de> for Bound {
9292
deserializer.deserialize_str(BoundVisitor)
9393
}
9494
}
95+
96+
#[derive(Debug)]
97+
pub struct StatisticSeries {
98+
pub artifact_ids: ArtifactIdIter,
99+
pub points: std::vec::IntoIter<Option<f64>>,
100+
}
101+
102+
impl Iterator for StatisticSeries {
103+
type Item = (ArtifactId, Option<f64>);
104+
fn next(&mut self) -> Option<Self::Item> {
105+
Some((self.artifact_ids.next()?, self.points.next().unwrap()))
106+
}
107+
108+
fn size_hint(&self) -> (usize, Option<usize>) {
109+
self.artifact_ids.size_hint()
110+
}
111+
}

site/src/selector.rs

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

28+
use database::selector::StatisticSeries;
29+
use database::ArtifactIdIter;
2830
use database::{selector::Bound, Benchmark, CodegenBackend, Commit, Connection, Index, Lookup};
2931

3032
use crate::comparison::Metric;
@@ -85,34 +87,6 @@ pub fn range_subset(data: Vec<Commit>, range: RangeInclusive<Bound>) -> Vec<Comm
8587
}
8688
}
8789

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

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

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

0 commit comments

Comments
 (0)