@@ -8,7 +8,7 @@ use chrono::{DateTime, TimeZone, Utc};
88use hashbrown:: HashMap ;
99use native_tls:: { Certificate , TlsConnector } ;
1010use postgres_native_tls:: MakeTlsConnector ;
11- use std:: convert:: TryFrom ;
11+ use std:: convert:: { TryFrom , TryInto } ;
1212use std:: str:: FromStr ;
1313use std:: sync:: Arc ;
1414use std:: time:: Duration ;
@@ -246,6 +246,14 @@ static MIGRATIONS: &[&str] = &[
246246 drop table error_series;
247247 alter table error_new rename to error;
248248"# ,
249+ r#"
250+ create table artifact_size(
251+ aid integer references artifact(id) on delete cascade on update cascade,
252+ component text not null,
253+ size integer not null,
254+ UNIQUE(aid, component)
255+ );
256+ "# ,
249257] ;
250258
251259#[ async_trait:: async_trait]
@@ -328,6 +336,7 @@ pub struct CachedStatements {
328336 select_runtime_pstat_series : Statement ,
329337 insert_runtime_pstat : Statement ,
330338 get_runtime_pstat : Statement ,
339+ record_artifact_size : Statement ,
331340}
332341
333342pub struct PostgresTransaction < ' a > {
@@ -513,7 +522,14 @@ impl PostgresConnection {
513522 order by sids.idx
514523 " )
515524 . await
516- . unwrap ( )
525+ . unwrap ( ) ,
526+ record_artifact_size : conn. prepare ( "
527+ insert into artifact_size (aid, component, size)
528+ values ($1, $2, $3)
529+ on conflict (aid, component)
530+ do update
531+ set size = excluded.size
532+ " ) . await . unwrap ( ) ,
517533 } ) ,
518534 conn,
519535 }
@@ -903,6 +919,17 @@ where
903919 . unwrap ( ) ;
904920 }
905921
922+ async fn record_artifact_size ( & self , artifact : ArtifactIdNumber , component : & str , size : u64 ) {
923+ let size: i32 = size. try_into ( ) . expect ( "Too large artifact" ) ;
924+ self . conn ( )
925+ . execute (
926+ & self . statements ( ) . record_artifact_size ,
927+ & [ & ( artifact. 0 as i32 ) , & component, & size] ,
928+ )
929+ . await
930+ . unwrap ( ) ;
931+ }
932+
906933 async fn artifact_id ( & self , artifact : & ArtifactId ) -> ArtifactIdNumber {
907934 let ( name, date, ty) = match artifact {
908935 ArtifactId :: Commit ( commit) => (
0 commit comments