fix logic for getting stop data

This commit is contained in:
2025-01-09 13:34:50 -08:00
parent 798a708793
commit 04a9d4494e

View File

@@ -305,7 +305,7 @@ ${json}`);
public async getStopsBySystemId(systemId: string): Promise<IStop[]> {
await this.updateStopsForSystemIdIfTTL(systemId);
if (!this.cache.stopsBySystemId || this.cache.stopsBySystemId[systemId]) {
if (!this.cache.stopsBySystemId || !this.cache.stopsBySystemId[systemId]) {
return [];
}
return this.cache.stopsBySystemId[systemId];
@@ -339,6 +339,10 @@ ${json}`);
if (json.stops) {
const jsonStops = Object.values(json.stops);
// TODO: restore normal cache behavior
this.cache.stopsBySystemId = {};
this.cache.stopByStopId = {};
await Promise.all(jsonStops.map(async (stop: any) => {
const constructedStop: IStop = {
name: stop.name,
@@ -350,13 +354,21 @@ ${json}`);
},
};
if (this.cache.stopsBySystemId) {
this.cache.stopsBySystemId[systemId]?.push(constructedStop);
if (!this.cache.stopsBySystemId) {
this.cache.stopsBySystemId = {};
}
if (this.cache.stopByStopId) {
this.cache.stopByStopId[constructedStop.id] = constructedStop;
if (!this.cache.stopsBySystemId[systemId]) {
this.cache.stopsBySystemId[systemId] = [];
}
this.cache.stopsBySystemId[systemId].push(constructedStop);
if (!this.cache.stopByStopId) {
this.cache.stopByStopId = {};
}
this.cache.stopByStopId[constructedStop.id] = constructedStop;
}));
}
} catch (e) {