@@ -5,12 +5,19 @@ use std::time::Instant;
5
5
use tokio_postgres:: types:: Type ;
6
6
use tokio_postgres:: Row ;
7
7
8
+ const ARTIFACT_JOIN_AND_WHERE : & str =
9
+ "join artifact on artifact.id = aid where artifact.date > (CURRENT_TIMESTAMP - interval '4 week')" ;
10
+ const ARTIFACT_WHERE : & str = "where artifact.date > (CURRENT_TIMESTAMP - interval '4 week')" ;
11
+
8
12
trait Table {
9
13
fn name ( ) -> & ' static str ;
10
14
fn copy_out ( ) -> & ' static str ;
11
15
fn insert ( ) -> & ' static str ;
12
16
fn types ( ) -> & ' static [ Type ] ;
13
17
fn execute ( statement : & mut rusqlite:: Statement , row : Row ) ;
18
+ fn trailer ( ) -> & ' static str {
19
+ ""
20
+ }
14
21
}
15
22
16
23
struct PstatSeries ;
@@ -51,6 +58,9 @@ impl Table for Pstat {
51
58
fn insert ( ) -> & ' static str {
52
59
"insert into pstat (series, aid, cid, value) VALUES (?, ?, ?, ?)"
53
60
}
61
+ fn trailer ( ) -> & ' static str {
62
+ ARTIFACT_JOIN_AND_WHERE
63
+ }
54
64
fn types ( ) -> & ' static [ Type ] {
55
65
& [ Type :: INT4 , Type :: INT2 , Type :: INT4 , Type :: FLOAT8 ]
56
66
}
@@ -144,6 +154,9 @@ impl Table for Artifact {
144
154
fn insert ( ) -> & ' static str {
145
155
"insert into artifact (id, name, date, type) VALUES (?, ?, ?, ?)"
146
156
}
157
+ fn trailer ( ) -> & ' static str {
158
+ ARTIFACT_WHERE
159
+ }
147
160
fn types ( ) -> & ' static [ Type ] {
148
161
& [ Type :: INT2 , Type :: TEXT , Type :: TIMESTAMPTZ , Type :: TEXT ]
149
162
}
@@ -217,6 +230,9 @@ impl Table for SelfProfileQuery {
217
230
fn insert ( ) -> & ' static str {
218
231
"insert into self_profile_query (series, aid, cid, self_time, blocked_time, incremental_load_time, number_of_cache_hits, invocation_count) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"
219
232
}
233
+ fn trailer ( ) -> & ' static str {
234
+ ARTIFACT_JOIN_AND_WHERE
235
+ }
220
236
fn types ( ) -> & ' static [ Type ] {
221
237
& [
222
238
Type :: INT4 ,
@@ -287,7 +303,13 @@ async fn copy<R: Table>(
287
303
let mut prepared = sqlite. prepare ( R :: insert ( ) ) . unwrap ( ) ;
288
304
let rows = postgres
289
305
. query_raw (
290
- format ! ( "select {} from {}" , R :: copy_out( ) , R :: name( ) ) . as_str ( ) ,
306
+ format ! (
307
+ "select {} from {}{}" ,
308
+ R :: copy_out( ) ,
309
+ R :: name( ) ,
310
+ R :: trailer( )
311
+ )
312
+ . as_str ( ) ,
291
313
vec ! [ ] ,
292
314
)
293
315
. await
0 commit comments