@@ -577,25 +577,7 @@ impl Connection for SqliteConnection {
577577 . optional ( )
578578 . unwrap ( ) ?;
579579
580- match ty. as_str ( ) {
581- "master" => Some ( ArtifactId :: Commit ( Commit {
582- sha : artifact. to_owned ( ) ,
583- date : Date (
584- Utc . timestamp_opt ( date. expect ( "master has date" ) , 0 )
585- . unwrap ( ) ,
586- ) ,
587- r#type : CommitType :: Master ,
588- } ) ) ,
589- "try" => Some ( ArtifactId :: Commit ( Commit {
590- sha : artifact. to_owned ( ) ,
591- date : date
592- . map ( |d| Date ( Utc . timestamp_opt ( d, 0 ) . unwrap ( ) ) )
593- . unwrap_or_else ( || Date :: ymd_hms ( 2000 , 1 , 1 , 0 , 0 , 0 ) ) ,
594- r#type : CommitType :: Try ,
595- } ) ) ,
596- "release" => Some ( ArtifactId :: Tag ( artifact. to_owned ( ) ) ) ,
597- _ => panic ! ( "unknown artifact type: {:?}" , ty) ,
598- }
580+ Some ( parse_artifact_id ( ty. as_str ( ) , artifact, date) )
599581 }
600582
601583 async fn record_duration ( & self , artifact : ArtifactIdNumber , duration : Duration ) {
@@ -1166,24 +1148,31 @@ impl Connection for SqliteConnection {
11661148 . collect ( )
11671149 }
11681150
1169- async fn last_artifact_collection ( & self ) -> Option < ArtifactCollection > {
1151+ async fn last_n_artifact_collections ( & self , n : u32 ) -> Vec < ArtifactCollection > {
11701152 self . raw_ref ( )
1171- . query_row (
1172- "select date_recorded, duration \
1173- from artifact_collection_duration \
1153+ . prepare_cached (
1154+ "select art.name, art.date, art.type, acd.date_recorded, acd.duration \
1155+ from artifact_collection_duration as acd \
1156+ join artifact as art on art.id = acd.aid \
11741157 order by date_recorded desc \
1175- limit 1;",
1176- params ! [ ] ,
1177- |r| {
1178- Ok ( (
1179- Utc . timestamp_opt ( r. get ( 0 ) ?, 0 ) . unwrap ( ) ,
1180- Duration :: from_secs ( r. get ( 1 ) ?) ,
1181- ) )
1182- } ,
1158+ limit ?;",
11831159 )
1184- . optional ( )
11851160 . unwrap ( )
1186- . map ( |( end_time, duration) | ArtifactCollection { end_time, duration } )
1161+ . query ( params ! [ & n] )
1162+ . unwrap ( )
1163+ . mapped ( |r| {
1164+ let sha = r. get :: < _ , String > ( 0 ) ?;
1165+ let date = r. get :: < _ , Option < i64 > > ( 1 ) ?;
1166+ let ty = r. get :: < _ , String > ( 2 ) ?;
1167+
1168+ Ok ( ArtifactCollection {
1169+ artifact : parse_artifact_id ( & ty, & sha, date) ,
1170+ end_time : Utc . timestamp_opt ( r. get ( 3 ) ?, 0 ) . unwrap ( ) ,
1171+ duration : Duration :: from_secs ( r. get ( 4 ) ?) ,
1172+ } )
1173+ } )
1174+ . collect :: < Result < Vec < _ > , _ > > ( )
1175+ . unwrap ( )
11871176 }
11881177
11891178 async fn parent_of ( & self , sha : & str ) -> Option < String > {
@@ -1252,3 +1241,25 @@ impl Connection for SqliteConnection {
12521241 . unwrap ( ) ;
12531242 }
12541243}
1244+
1245+ fn parse_artifact_id ( ty : & str , sha : & str , date : Option < i64 > ) -> ArtifactId {
1246+ match ty {
1247+ "master" => ArtifactId :: Commit ( Commit {
1248+ sha : sha. to_owned ( ) ,
1249+ date : Date (
1250+ Utc . timestamp_opt ( date. expect ( "master has date" ) , 0 )
1251+ . unwrap ( ) ,
1252+ ) ,
1253+ r#type : CommitType :: Master ,
1254+ } ) ,
1255+ "try" => ArtifactId :: Commit ( Commit {
1256+ sha : sha. to_owned ( ) ,
1257+ date : date
1258+ . map ( |d| Date ( Utc . timestamp_opt ( d, 0 ) . unwrap ( ) ) )
1259+ . unwrap_or_else ( || Date :: ymd_hms ( 2000 , 1 , 1 , 0 , 0 , 0 ) ) ,
1260+ r#type : CommitType :: Try ,
1261+ } ) ,
1262+ "release" => ArtifactId :: Tag ( sha. to_owned ( ) ) ,
1263+ _ => panic ! ( "unknown artifact type: {:?}" , ty) ,
1264+ }
1265+ }
0 commit comments