@@ -123,7 +123,13 @@ struct RefreshResponse {
123
123
)
124
124
) ]
125
125
async fn refresh (
126
- app_state : State < AppState > ,
126
+ State ( AppState {
127
+ db_pool,
128
+ valkey : valkey_client,
129
+ infra_caches,
130
+ map_layers,
131
+ ..
132
+ } ) : State < AppState > ,
127
133
Extension ( auth) : AuthenticationExt ,
128
134
Query ( query_params) : Query < RefreshQueryParams > ,
129
135
) -> Result < Json < RefreshResponse > > {
@@ -135,11 +141,6 @@ async fn refresh(
135
141
return Err ( AuthorizationError :: Unauthorized . into ( ) ) ;
136
142
}
137
143
138
- let db_pool = app_state. db_pool . clone ( ) ;
139
- let valkey_client = app_state. valkey . clone ( ) ;
140
- let infra_caches = app_state. infra_caches . clone ( ) ;
141
- let map_layers = app_state. map_layers . clone ( ) ;
142
-
143
144
// Use a transaction to give scope to infra list lock
144
145
let RefreshQueryParams {
145
146
force,
@@ -160,7 +161,6 @@ async fn refresh(
160
161
} ;
161
162
162
163
// Refresh each infras
163
- let db_pool = db_pool;
164
164
let mut infra_refreshed = vec ! [ ] ;
165
165
166
166
for mut infra in infras_list {
@@ -201,7 +201,11 @@ struct InfraListResponse {
201
201
) ,
202
202
) ]
203
203
async fn list (
204
- app_state : State < AppState > ,
204
+ State ( AppState {
205
+ db_pool,
206
+ osrdyne_client,
207
+ ..
208
+ } ) : State < AppState > ,
205
209
Extension ( auth) : AuthenticationExt ,
206
210
pagination_params : Query < PaginationQueryParams > ,
207
211
) -> Result < Json < InfraListResponse > > {
@@ -212,8 +216,6 @@ async fn list(
212
216
if !authorized {
213
217
return Err ( AuthorizationError :: Unauthorized . into ( ) ) ;
214
218
}
215
- let db_pool = app_state. db_pool . clone ( ) ;
216
- let osrdyne_client = app_state. osrdyne_client . clone ( ) ;
217
219
218
220
let settings = pagination_params
219
221
. validate ( 1000 ) ?
@@ -295,7 +297,11 @@ struct InfraIdParam {
295
297
) ,
296
298
) ]
297
299
async fn get (
298
- app_state : State < AppState > ,
300
+ State ( AppState {
301
+ db_pool,
302
+ osrdyne_client,
303
+ ..
304
+ } ) : State < AppState > ,
299
305
Extension ( auth) : AuthenticationExt ,
300
306
Path ( infra) : Path < InfraIdParam > ,
301
307
) -> Result < Json < InfraWithState > > {
@@ -307,9 +313,6 @@ async fn get(
307
313
return Err ( AuthorizationError :: Unauthorized . into ( ) ) ;
308
314
}
309
315
310
- let db_pool = app_state. db_pool . clone ( ) ;
311
- let osrdyne_client = app_state. osrdyne_client . clone ( ) ;
312
-
313
316
let infra_id = infra. infra_id ;
314
317
let infra = Infra :: retrieve_or_fail ( & mut db_pool. get ( ) . await ?, infra_id, || {
315
318
InfraApiError :: NotFound { infra_id }
@@ -344,7 +347,7 @@ impl From<InfraCreateForm> for Changeset<Infra> {
344
347
) ,
345
348
) ]
346
349
async fn create (
347
- db_pool : State < DbConnectionPoolV2 > ,
350
+ State ( db_pool) : State < DbConnectionPoolV2 > ,
348
351
Extension ( auth) : AuthenticationExt ,
349
352
Json ( infra_form) : Json < InfraCreateForm > ,
350
353
) -> Result < impl IntoResponse > {
@@ -381,7 +384,7 @@ struct CloneQuery {
381
384
async fn clone (
382
385
Extension ( auth) : AuthenticationExt ,
383
386
Path ( params) : Path < InfraIdParam > ,
384
- db_pool : State < DbConnectionPoolV2 > ,
387
+ State ( db_pool) : State < DbConnectionPoolV2 > ,
385
388
Query ( CloneQuery { name } ) : Query < CloneQuery > ,
386
389
) -> Result < Json < i64 > > {
387
390
let authorized = auth
@@ -421,7 +424,11 @@ async fn clone(
421
424
) ,
422
425
) ]
423
426
async fn delete (
424
- app_state : State < AppState > ,
427
+ State ( AppState {
428
+ db_pool,
429
+ infra_caches,
430
+ ..
431
+ } ) : State < AppState > ,
425
432
Extension ( auth) : AuthenticationExt ,
426
433
infra : Path < InfraIdParam > ,
427
434
) -> Result < impl IntoResponse > {
@@ -433,8 +440,6 @@ async fn delete(
433
440
return Err ( AuthorizationError :: Unauthorized . into ( ) ) ;
434
441
}
435
442
436
- let db_pool = app_state. db_pool . clone ( ) ;
437
- let infra_caches = app_state. infra_caches . clone ( ) ;
438
443
let infra_id = infra. infra_id ;
439
444
if Infra :: fast_delete_static ( db_pool. get ( ) . await ?, infra_id) . await ? {
440
445
infra_caches. remove ( & infra_id) ;
@@ -468,7 +473,7 @@ impl From<InfraPatchForm> for Changeset<Infra> {
468
473
) ,
469
474
) ]
470
475
async fn put (
471
- db_pool : State < DbConnectionPoolV2 > ,
476
+ State ( db_pool) : State < DbConnectionPoolV2 > ,
472
477
Extension ( auth) : AuthenticationExt ,
473
478
Path ( infra) : Path < i64 > ,
474
479
Json ( patch) : Json < InfraPatchForm > ,
@@ -501,7 +506,11 @@ async fn put(
501
506
)
502
507
) ]
503
508
async fn get_switch_types (
504
- app_state : State < AppState > ,
509
+ State ( AppState {
510
+ db_pool,
511
+ infra_caches,
512
+ ..
513
+ } ) : State < AppState > ,
505
514
Extension ( auth) : AuthenticationExt ,
506
515
Path ( infra) : Path < InfraIdParam > ,
507
516
) -> Result < Json < Vec < SwitchType > > > {
@@ -513,9 +522,7 @@ async fn get_switch_types(
513
522
return Err ( AuthorizationError :: Unauthorized . into ( ) ) ;
514
523
}
515
524
516
- let db_pool = app_state. db_pool . clone ( ) ;
517
525
let conn = & mut db_pool. get ( ) . await ?;
518
- let infra_caches = app_state. infra_caches . clone ( ) ;
519
526
520
527
let infra = Infra :: retrieve_or_fail ( conn, infra. infra_id , || InfraApiError :: NotFound {
521
528
infra_id : infra. infra_id ,
@@ -546,7 +553,7 @@ async fn get_switch_types(
546
553
async fn get_speed_limit_tags (
547
554
Extension ( auth) : AuthenticationExt ,
548
555
Path ( infra) : Path < InfraIdParam > ,
549
- db_pool : State < DbConnectionPoolV2 > ,
556
+ State ( db_pool) : State < DbConnectionPoolV2 > ,
550
557
) -> Result < Json < Vec < String > > > {
551
558
let authorized = auth
552
559
. check_roles ( [ BuiltinRole :: InfraRead ] . into ( ) )
@@ -590,7 +597,7 @@ async fn get_voltages(
590
597
Extension ( auth) : AuthenticationExt ,
591
598
Path ( infra) : Path < InfraIdParam > ,
592
599
Query ( param) : Query < GetVoltagesQueryParams > ,
593
- db_pool : State < DbConnectionPoolV2 > ,
600
+ State ( db_pool) : State < DbConnectionPoolV2 > ,
594
601
) -> Result < Json < Vec < String > > > {
595
602
let authorized = auth
596
603
. check_roles ( [ BuiltinRole :: InfraRead ] . into ( ) )
@@ -623,7 +630,7 @@ async fn get_voltages(
623
630
)
624
631
) ]
625
632
async fn get_all_voltages (
626
- db_pool : State < DbConnectionPoolV2 > ,
633
+ State ( db_pool) : State < DbConnectionPoolV2 > ,
627
634
Extension ( auth) : AuthenticationExt ,
628
635
) -> Result < Json < Vec < String > > > {
629
636
let authorized = auth
@@ -712,7 +719,11 @@ async fn unlock(
712
719
)
713
720
) ]
714
721
async fn load (
715
- app_state : State < AppState > ,
722
+ State ( AppState {
723
+ db_pool,
724
+ core_client,
725
+ ..
726
+ } ) : State < AppState > ,
716
727
Extension ( auth) : AuthenticationExt ,
717
728
Path ( path) : Path < InfraIdParam > ,
718
729
) -> Result < impl IntoResponse > {
@@ -724,9 +735,6 @@ async fn load(
724
735
return Err ( AuthorizationError :: Unauthorized . into ( ) ) ;
725
736
}
726
737
727
- let db_pool = app_state. db_pool . clone ( ) ;
728
- let core_client = app_state. core_client . clone ( ) ;
729
-
730
738
let infra_id = path. infra_id ;
731
739
let infra = Infra :: retrieve_or_fail ( & mut db_pool. get ( ) . await ?, infra_id, || {
732
740
InfraApiError :: NotFound { infra_id }
0 commit comments