Skip to content

Commit b4b4818

Browse files
committed
Load artifact sizes from the DB in the /get endpoint
1 parent f8cc0b2 commit b4b4818

File tree

6 files changed

+41
-3
lines changed

6 files changed

+41
-3
lines changed

database/src/pool.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ pub trait Connection: Send + Sync {
9191
/// bytes.
9292
async fn record_artifact_size(&self, artifact: ArtifactIdNumber, component: &str, size: u64);
9393

94+
/// Returns the sizes of individual components of a single artifact.
95+
async fn get_artifact_size(&self, aid: ArtifactIdNumber) -> HashMap<String, u64>;
96+
9497
/// Returns vector of bootstrap build times for the given artifacts. The kth
9598
/// element is the minimum build time for the kth artifact in `aids`, across
9699
/// all collections for the artifact, or none if there is no bootstrap data

database/src/pool/postgres.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ pub struct CachedStatements {
337337
insert_runtime_pstat: Statement,
338338
get_runtime_pstat: Statement,
339339
record_artifact_size: Statement,
340+
get_artifact_size: Statement,
340341
}
341342

342343
pub struct PostgresTransaction<'a> {
@@ -530,6 +531,10 @@ impl PostgresConnection {
530531
do update
531532
set size = excluded.size
532533
").await.unwrap(),
534+
get_artifact_size: conn.prepare("
535+
select component, size from artifact_size
536+
where aid = $1
537+
").await.unwrap()
533538
}),
534539
conn,
535540
}
@@ -930,6 +935,18 @@ where
930935
.unwrap();
931936
}
932937

938+
async fn get_artifact_size(&self, aid: ArtifactIdNumber) -> HashMap<String, u64> {
939+
let rows = self
940+
.conn()
941+
.query(&self.statements().get_artifact_size, &[&aid.0])
942+
.await
943+
.unwrap();
944+
945+
rows.into_iter()
946+
.map(|row| (row.get::<_, String>(0), row.get::<_, u32>(1) as u64))
947+
.collect()
948+
}
949+
933950
async fn artifact_id(&self, artifact: &ArtifactId) -> ArtifactIdNumber {
934951
let (name, date, ty) = match artifact {
935952
ArtifactId::Commit(commit) => (

database/src/pool/sqlite.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,18 @@ impl Connection for SqliteConnection {
812812
.unwrap();
813813
}
814814

815+
async fn get_artifact_size(&self, aid: ArtifactIdNumber) -> HashMap<String, u64> {
816+
self.raw_ref()
817+
.prepare("select component, size from artifact_size where aid = ?")
818+
.unwrap()
819+
.query_map(params![&aid.0], |row| {
820+
Ok((row.get::<_, String>(0)?, row.get::<_, u64>(1)?))
821+
})
822+
.unwrap()
823+
.map(|r| r.unwrap())
824+
.collect()
825+
}
826+
815827
async fn get_bootstrap(&self, aids: &[ArtifactIdNumber]) -> Vec<Option<Duration>> {
816828
aids.iter()
817829
.map(|aid| {

site/frontend/src/pages/compare/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export interface ArtifactDescription {
2222
pr: number | null;
2323
bootstrap: Dict<number>;
2424
bootstrap_total: number;
25+
component_sizes: Dict<number>;
2526
}
2627

2728
export interface StatComparison {

site/src/api.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ pub mod comparison {
187187
pub pr: Option<u32>,
188188
pub bootstrap: HashMap<String, u64>,
189189
pub bootstrap_total: u64,
190+
pub component_sizes: HashMap<String, u64>,
190191
}
191192

192193
#[derive(Debug, Clone, Serialize)]

site/src/comparison.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,7 @@ pub struct ArtifactDescription {
925925
/// Bootstrap data in the form "$crate" -> nanoseconds
926926
pub bootstrap: HashMap<String, u64>,
927927
pub bootstrap_total: u64,
928+
pub component_sizes: HashMap<String, u64>,
928929
}
929930

930931
type StatisticsMap<TestCase> = HashMap<TestCase, f64>;
@@ -939,9 +940,8 @@ impl ArtifactDescription {
939940
artifact: ArtifactId,
940941
master_commits: &[collector::MasterCommit],
941942
) -> Self {
942-
let bootstrap = conn
943-
.get_bootstrap_by_crate(&[conn.artifact_id(&artifact).await])
944-
.await;
943+
let aid = conn.artifact_id(&artifact).await;
944+
let bootstrap = conn.get_bootstrap_by_crate(&[aid]).await;
945945
let bootstrap_total = bootstrap
946946
.values()
947947
.filter_map(|v| {
@@ -979,11 +979,14 @@ impl ArtifactDescription {
979979
None
980980
};
981981

982+
let component_sizes = conn.get_artifact_size(aid).await.into_iter().collect();
983+
982984
Self {
983985
pr,
984986
artifact,
985987
bootstrap,
986988
bootstrap_total,
989+
component_sizes,
987990
}
988991
}
989992
}
@@ -1023,6 +1026,7 @@ impl From<ArtifactDescription> for api::comparison::ArtifactDescription {
10231026
pr: data.pr,
10241027
bootstrap: data.bootstrap,
10251028
bootstrap_total: data.bootstrap_total,
1029+
component_sizes: data.component_sizes,
10261030
}
10271031
}
10281032
}

0 commit comments

Comments
 (0)