Skip to content

Commit

Permalink
fixup! editoast: improve performance of batch_pathfinding function
Browse files Browse the repository at this point in the history
  • Loading branch information
flomonster committed Jul 12, 2024
1 parent 089d5bb commit 84821ac
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions editoast/src/views/v2/path/path_item_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct PathItemCache {
uic_to_ops: HashMap<i64, Vec<OperationalPointModel>>,
trigram_to_ops: HashMap<String, Vec<OperationalPointModel>>,
ids_to_ops: HashMap<String, OperationalPointModel>,
valid_tracks: HashSet<String>,
existing_track_ids: HashSet<String>,
}

impl PathItemCache {
Expand Down Expand Up @@ -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,
})
}

Expand All @@ -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
Expand Down

0 comments on commit 84821ac

Please sign in to comment.