Commit 7b37385 1 parent 78d3f31 commit 7b37385 Copy full SHA for 7b37385
File tree 1 file changed +13
-2
lines changed
1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change
1
+ use std:: collections:: HashMap ;
2
+
1
3
use crate :: diesel:: QueryDsl ;
2
4
use crate :: error:: Result ;
3
5
use crate :: models:: LightRollingStockModel ;
@@ -212,9 +214,18 @@ pub async fn get_timetable_train_schedules_with_simulations(
212
214
let simulation_outputs = SimulationOutput :: belonging_to ( & train_schedules)
213
215
. load :: < SimulationOutput > ( & mut conn)
214
216
. await ?;
215
- let result = train_schedules
217
+ let mut output_map: HashMap < _ , _ > = simulation_outputs
218
+ . into_iter ( )
219
+ . map ( |o| ( o. train_schedule_id . unwrap ( ) , o) )
220
+ . collect ( ) ;
221
+ let result: Vec < ( TrainSchedule , SimulationOutput ) > = train_schedules
216
222
. into_iter ( )
217
- . zip ( simulation_outputs)
223
+ . filter_map ( |schedule| {
224
+ schedule
225
+ . id
226
+ . and_then ( |id| output_map. remove ( & id) )
227
+ . map ( |output| ( schedule, output) )
228
+ } )
218
229
. collect ( ) ;
219
230
Ok ( result)
220
231
}
You can’t perform that action at this time.
0 commit comments