ParkingReformNetwork / parking-lot-map

Interactive map showing how much of downtowns are dominated by parking
https://parkingreform.org/parking-lot-map/
MIT License
1 stars 5 forks source link

Fix lot data double loading #257

Closed Eric-Arellano closed 3 months ago

Eric-Arellano commented 3 months ago

Before, it was possible to load parking lot data multiple times due to race conditions. If we had >1 event triggering a map load, then we'd have two requests concurrently.

We need a thread-safe way to only load the data once, i.e. something that keeps track of in-flight requests. We can do that with a Map<CityId, Promise>, which makes sure we never have more than one Promise for a given city. Once the Promise is complete, we then add the city to ParkingLotLoader.loadedCities.