@@ -577,25 +577,7 @@ impl Connection for SqliteConnection {
577
577
. optional ( )
578
578
. unwrap ( ) ?;
579
579
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) )
599
581
}
600
582
601
583
async fn record_duration ( & self , artifact : ArtifactIdNumber , duration : Duration ) {
@@ -1162,24 +1144,31 @@ impl Connection for SqliteConnection {
1162
1144
. collect ( )
1163
1145
}
1164
1146
1165
- async fn last_artifact_collection ( & self ) -> Option < ArtifactCollection > {
1147
+ async fn last_n_artifact_collections ( & self , n : u32 ) -> Vec < ArtifactCollection > {
1166
1148
self . raw_ref ( )
1167
- . query_row (
1168
- "select date_recorded, duration \
1169
- from artifact_collection_duration \
1149
+ . prepare_cached (
1150
+ "select art.name, art.date, art.type, acd.date_recorded, acd.duration \
1151
+ from artifact_collection_duration as acd \
1152
+ join artifact as art on art.id = acd.aid \
1170
1153
order by date_recorded desc \
1171
- limit 1;",
1172
- params ! [ ] ,
1173
- |r| {
1174
- Ok ( (
1175
- Utc . timestamp_opt ( r. get ( 0 ) ?, 0 ) . unwrap ( ) ,
1176
- Duration :: from_secs ( r. get ( 1 ) ?) ,
1177
- ) )
1178
- } ,
1154
+ limit ?;",
1179
1155
)
1180
- . optional ( )
1181
1156
. unwrap ( )
1182
- . map ( |( end_time, duration) | ArtifactCollection { end_time, duration } )
1157
+ . query ( params ! [ & n] )
1158
+ . unwrap ( )
1159
+ . mapped ( |r| {
1160
+ let sha = r. get :: < _ , String > ( 0 ) ?;
1161
+ let date = r. get :: < _ , Option < i64 > > ( 1 ) ?;
1162
+ let ty = r. get :: < _ , String > ( 2 ) ?;
1163
+
1164
+ Ok ( ArtifactCollection {
1165
+ artifact : parse_artifact_id ( & ty, & sha, date) ,
1166
+ end_time : Utc . timestamp_opt ( r. get ( 3 ) ?, 0 ) . unwrap ( ) ,
1167
+ duration : Duration :: from_secs ( r. get ( 4 ) ?) ,
1168
+ } )
1169
+ } )
1170
+ . collect :: < Result < Vec < _ > , _ > > ( )
1171
+ . unwrap ( )
1183
1172
}
1184
1173
1185
1174
async fn parent_of ( & self , sha : & str ) -> Option < String > {
@@ -1239,3 +1228,25 @@ impl Connection for SqliteConnection {
1239
1228
. unwrap ( )
1240
1229
}
1241
1230
}
1231
+
1232
+ fn parse_artifact_id ( ty : & str , sha : & str , date : Option < i64 > ) -> ArtifactId {
1233
+ match ty {
1234
+ "master" => ArtifactId :: Commit ( Commit {
1235
+ sha : sha. to_owned ( ) ,
1236
+ date : Date (
1237
+ Utc . timestamp_opt ( date. expect ( "master has date" ) , 0 )
1238
+ . unwrap ( ) ,
1239
+ ) ,
1240
+ r#type : CommitType :: Master ,
1241
+ } ) ,
1242
+ "try" => ArtifactId :: Commit ( Commit {
1243
+ sha : sha. to_owned ( ) ,
1244
+ date : date
1245
+ . map ( |d| Date ( Utc . timestamp_opt ( d, 0 ) . unwrap ( ) ) )
1246
+ . unwrap_or_else ( || Date :: ymd_hms ( 2000 , 1 , 1 , 0 , 0 , 0 ) ) ,
1247
+ r#type : CommitType :: Try ,
1248
+ } ) ,
1249
+ "release" => ArtifactId :: Tag ( sha. to_owned ( ) ) ,
1250
+ _ => panic ! ( "unknown artifact type: {:?}" , ty) ,
1251
+ }
1252
+ }
0 commit comments