@@ -295,6 +295,22 @@ impl CurrentConfiguration {
295295 }
296296}
297297
298+ impl CurrentConfiguration {
299+ async fn for_config (
300+ db_config : BeamlineConfiguration ,
301+ nt : & NumTracker ,
302+ ) -> async_graphql:: Result < Self > {
303+ let dir = nt
304+ . for_beamline ( db_config. name ( ) , db_config. tracker_file_extension ( ) )
305+ . await ?;
306+ let high_file = dir. prev ( ) . await ?;
307+ Ok ( CurrentConfiguration {
308+ db_config,
309+ high_file,
310+ } )
311+ }
312+ }
313+
298314impl FieldSource < ScanField > for ScanPaths {
299315 fn resolve ( & self , field : & ScanField ) -> Cow < ' _ , str > {
300316 match field {
@@ -346,14 +362,7 @@ impl Query {
346362 let nt = ctx. data :: < NumTracker > ( ) ?;
347363 trace ! ( "Getting config for {beamline:?}" ) ;
348364 let conf = db. current_configuration ( & beamline) . await ?;
349- let dir = nt
350- . for_beamline ( & beamline, conf. tracker_file_extension ( ) )
351- . await ?;
352- let high_file = dir. prev ( ) . await ?;
353- Ok ( CurrentConfiguration {
354- db_config : conf,
355- high_file,
356- } )
365+ CurrentConfiguration :: for_config ( conf, nt) . await
357366 }
358367
359368 /// Get the configurations for all available beamlines
@@ -372,16 +381,11 @@ impl Query {
372381 None => db. all_configurations ( ) . await ?,
373382 } ;
374383
375- futures:: future:: join_all ( configurations. into_iter ( ) . map ( |cnf| async {
376- let dir = nt
377- . for_beamline ( cnf. name ( ) , cnf. tracker_file_extension ( ) )
378- . await ?;
379- let high_file = dir. prev ( ) . await ?;
380- Ok ( CurrentConfiguration {
381- db_config : cnf,
382- high_file,
383- } )
384- } ) )
384+ futures:: future:: join_all (
385+ configurations
386+ . into_iter ( )
387+ . map ( |cnf| CurrentConfiguration :: for_config ( cnf, nt) ) ,
388+ )
385389 . await
386390 . into_iter ( )
387391 . collect ( )
@@ -448,14 +452,7 @@ impl Mutation {
448452 Some ( bc) => bc,
449453 None => upd. insert_new ( db) . await ?,
450454 } ;
451- let dir = nt
452- . for_beamline ( & beamline, db_config. tracker_file_extension ( ) )
453- . await ?;
454- let high_file = dir. prev ( ) . await ?;
455- Ok ( CurrentConfiguration {
456- db_config,
457- high_file,
458- } )
455+ CurrentConfiguration :: for_config ( db_config, nt) . await
459456 }
460457}
461458
0 commit comments