5
5
use diesel:: dsl:: sql;
6
6
use diesel:: prelude:: {
7
7
ExpressionMethods , JoinOnDsl , NullableExpressionMethods , OptionalExtension , PgConnection ,
8
- QueryDsl , RunQueryDsl ,
8
+ QueryDsl , RunQueryDsl , SelectableHelper as _ ,
9
9
} ;
10
10
use diesel_derives:: Associations ;
11
11
use git_testament:: { git_testament, git_testament_macros} ;
@@ -39,26 +39,21 @@ const CARGO_PKG_VERSION_PATCH: &str = env!("CARGO_PKG_VERSION_PATCH");
39
39
40
40
type Bytes = Vec < u8 > ;
41
41
42
- #[ derive( Queryable , QueryableByName ) ]
42
+ #[ derive( Queryable , Selectable ) ]
43
43
#[ diesel( table_name = subgraph_deployment) ]
44
44
// We map all fields to make loading `Detail` with diesel easier, but we
45
45
// don't need all the fields
46
- #[ allow( dead_code) ]
47
46
pub struct DeploymentDetail {
48
47
pub id : DeploymentId ,
49
48
pub deployment : String ,
50
49
pub failed : bool ,
51
50
health : HealthType ,
52
51
pub synced_at : Option < DateTime < Utc > > ,
53
52
pub synced_at_block_number : Option < i32 > ,
54
- fatal_error : Option < String > ,
55
- non_fatal_errors : Vec < String > ,
56
53
/// The earliest block for which we have history
57
54
pub earliest_block_number : i32 ,
58
55
pub latest_ethereum_block_hash : Option < Bytes > ,
59
56
pub latest_ethereum_block_number : Option < BigDecimal > ,
60
- last_healthy_ethereum_block_hash : Option < Bytes > ,
61
- last_healthy_ethereum_block_number : Option < BigDecimal > ,
62
57
pub entity_count : BigDecimal ,
63
58
graft_base : Option < String > ,
64
59
graft_block_hash : Option < Bytes > ,
@@ -67,10 +62,9 @@ pub struct DeploymentDetail {
67
62
reorg_count : i32 ,
68
63
current_reorg_depth : i32 ,
69
64
max_reorg_depth : i32 ,
70
- firehose_cursor : Option < String > ,
71
65
}
72
66
73
- #[ derive( Queryable , QueryableByName ) ]
67
+ #[ derive( Queryable , Selectable ) ]
74
68
#[ diesel( table_name = subgraph_error) ]
75
69
// We map all fields to make loading `Detail` with diesel easier, but we
76
70
// don't need all the fields
@@ -193,16 +187,18 @@ pub(crate) fn info_from_details(
193
187
failed : _,
194
188
health,
195
189
synced_at,
196
- fatal_error : _,
197
- non_fatal_errors : _,
198
190
earliest_block_number,
199
191
latest_ethereum_block_hash,
200
192
latest_ethereum_block_number,
201
193
entity_count,
202
194
graft_base : _,
203
195
graft_block_hash : _,
204
196
graft_block_number : _,
205
- ..
197
+ synced_at_block_number : _,
198
+ debug_fork : _,
199
+ reorg_count : _,
200
+ current_reorg_depth : _,
201
+ max_reorg_depth : _,
206
202
} = detail;
207
203
208
204
let site = sites
@@ -261,12 +257,15 @@ pub(crate) fn deployment_details(
261
257
) -> Result < Vec < DeploymentDetail > , StoreError > {
262
258
use subgraph_deployment as d;
263
259
260
+ let cols = DeploymentDetail :: as_select ( ) ;
261
+
264
262
// Empty deployments means 'all of them'
265
263
let details = if deployments. is_empty ( ) {
266
- d:: table. load :: < DeploymentDetail > ( conn) ?
264
+ d:: table. select ( cols ) . load :: < DeploymentDetail > ( conn) ?
267
265
} else {
268
266
d:: table
269
267
. filter ( d:: deployment. eq_any ( & deployments) )
268
+ . select ( cols)
270
269
. load :: < DeploymentDetail > ( conn) ?
271
270
} ;
272
271
Ok ( details)
@@ -278,8 +277,12 @@ pub(crate) fn deployment_details_for_id(
278
277
deployment : & DeploymentId ,
279
278
) -> Result < DeploymentDetail , StoreError > {
280
279
use subgraph_deployment as d;
280
+
281
+ let cols = DeploymentDetail :: as_select ( ) ;
282
+
281
283
d:: table
282
284
. filter ( d:: id. eq ( & deployment) )
285
+ . select ( cols)
283
286
. first :: < DeploymentDetail > ( conn)
284
287
. map_err ( StoreError :: from)
285
288
}
@@ -299,15 +302,19 @@ pub(crate) fn deployment_statuses(
299
302
let details_with_fatal_error = {
300
303
let join = e:: table. on ( e:: id. nullable ( ) . eq ( d:: fatal_error) ) ;
301
304
305
+ let cols = <( DeploymentDetail , Option < ErrorDetail > ) >:: as_select ( ) ;
306
+
302
307
// Empty deployments means 'all of them'
303
308
if sites. is_empty ( ) {
304
309
d:: table
305
310
. left_outer_join ( join)
311
+ . select ( cols)
306
312
. load :: < ( DeploymentDetail , Option < ErrorDetail > ) > ( conn) ?
307
313
} else {
308
314
d:: table
309
315
. left_outer_join ( join)
310
316
. filter ( d:: id. eq_any ( sites. iter ( ) . map ( |site| site. id ) ) )
317
+ . select ( cols)
311
318
. load :: < ( DeploymentDetail , Option < ErrorDetail > ) > ( conn) ?
312
319
}
313
320
} ;
@@ -480,7 +487,8 @@ pub fn deployment_entity(
480
487
481
488
let detail = d:: table
482
489
. find ( site. id )
483
- . first :: < crate :: detail:: DeploymentDetail > ( conn) ?;
490
+ . select ( DeploymentDetail :: as_select ( ) )
491
+ . first :: < DeploymentDetail > ( conn) ?;
484
492
485
493
StoredDeploymentEntity ( detail, manifest) . as_subgraph_deployment ( schema)
486
494
}
0 commit comments