@@ -51,6 +51,10 @@ pub fn root_schema_builder(
5151 AutoProcProgramDataLoader :: new ( database. clone ( ) ) ,
5252 tokio:: spawn,
5353 ) )
54+ . data ( DataLoader :: new (
55+ AutoProcDataLoader :: new ( database. clone ( ) ) ,
56+ tokio:: spawn,
57+ ) )
5458 . data ( database)
5559 . enable_federation ( )
5660}
@@ -64,6 +68,7 @@ pub struct ProcessingJobDataLoader(DatabaseConnection);
6468pub struct ProcessingJobParameterDataLoader ( DatabaseConnection ) ;
6569pub struct AutoProcIntegrationDataLoader ( DatabaseConnection ) ;
6670pub struct AutoProcProgramDataLoader ( DatabaseConnection ) ;
71+ pub struct AutoProcDataLoader ( DatabaseConnection ) ;
6772
6873impl ProcessingJobDataLoader {
6974 fn new ( database : DatabaseConnection ) -> Self {
@@ -95,6 +100,12 @@ impl AutoProcProgramDataLoader {
95100 }
96101}
97102
103+ impl AutoProcDataLoader {
104+ fn new ( database : DatabaseConnection ) -> Self {
105+ Self ( database)
106+ }
107+ }
108+
98109impl Loader < u32 > for ProcessedDataLoader {
99110 type Value = DataProcessing ;
100111 type Error = async_graphql:: Error ;
@@ -220,6 +231,29 @@ impl Loader<u32> for AutoProcProgramDataLoader {
220231 }
221232}
222233
234+ impl Loader < u32 > for AutoProcDataLoader {
235+ type Value = AutoProc ;
236+ type Error = async_graphql:: Error ;
237+
238+ #[ instrument( name = "load_auto_proc" , skip( self ) ) ]
239+ async fn load ( & self , keys : & [ u32 ] ) -> Result < HashMap < u32 , Self :: Value > , Self :: Error > {
240+ let mut results = HashMap :: new ( ) ;
241+ let keys_vec: Vec < u32 > = keys. iter ( ) . cloned ( ) . collect ( ) ;
242+ let records = auto_proc:: Entity :: find ( )
243+ . filter ( auto_proc:: Column :: AutoProcProgramId . is_in ( keys_vec) )
244+ . all ( & self . 0 )
245+ . await ?;
246+
247+ for record in records {
248+ let program_id = record. auto_proc_program_id . unwrap ( ) ;
249+ let data = AutoProc :: from ( record) ;
250+ results. insert ( program_id, data) ;
251+ }
252+
253+ Ok ( results)
254+ }
255+ }
256+
223257#[ ComplexObject ]
224258impl DataCollection {
225259 /// Fetched all the processed data from data collection during a session
@@ -297,12 +331,8 @@ impl AutoProcIntegration {
297331impl AutoProcProgram {
298332 /// Fetched the automatic process
299333 async fn auto_proc ( & self , ctx : & Context < ' _ > ) -> async_graphql:: Result < Option < AutoProc > > {
300- let database = ctx. data :: < DatabaseConnection > ( ) ?;
301- Ok ( auto_proc:: Entity :: find ( )
302- . filter ( auto_proc:: Column :: AutoProcProgramId . eq ( self . auto_proc_program_id ) )
303- . one ( database)
304- . await ?
305- . map ( AutoProc :: from) )
334+ let loader = ctx. data_unchecked :: < DataLoader < AutoProcDataLoader > > ( ) ;
335+ Ok ( loader. load_one ( self . auto_proc_program_id ) . await ?)
306336 }
307337}
308338
0 commit comments