From 84821ac554b3c5f5874a6c4d6d97063532ee1507 Mon Sep 17 00:00:00 2001 From: Florian Amsallem Date: Fri, 12 Jul 2024 16:10:09 +0200 Subject: [PATCH] fixup! editoast: improve performance of batch_pathfinding function --- editoast/src/views/v2/path/path_item_cache.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/editoast/src/views/v2/path/path_item_cache.rs b/editoast/src/views/v2/path/path_item_cache.rs index 19012d417a0..4077758ae23 100644 --- a/editoast/src/views/v2/path/path_item_cache.rs +++ b/editoast/src/views/v2/path/path_item_cache.rs @@ -18,7 +18,7 @@ pub struct PathItemCache { uic_to_ops: HashMap>, trigram_to_ops: HashMap>, ids_to_ops: HashMap, - valid_tracks: HashSet, + existing_track_ids: HashSet, } impl PathItemCache { @@ -46,17 +46,18 @@ impl PathItemCache { .flat_map(|op| &op.parts) .map(|part| (infra_id, part.track.0.clone())) .chain(tracks); - let valid_tracks = TrackSectionModel::retrieve_batch_unchecked::<_, Vec<_>>(conn, tracks) - .await? - .into_iter() - .map(|track| track.obj_id) - .collect(); + let existing_track_ids = + TrackSectionModel::retrieve_batch_unchecked::<_, Vec<_>>(conn, tracks) + .await? + .into_iter() + .map(|track| track.obj_id) + .collect(); Ok(PathItemCache { uic_to_ops, trigram_to_ops, ids_to_ops, - valid_tracks, + existing_track_ids, }) } @@ -77,7 +78,7 @@ impl PathItemCache { /// Check if a track exists pub fn track_exists(&self, track: &String) -> bool { - self.valid_tracks.contains(track) + self.existing_track_ids.contains(track) } /// Extract locations from path items