diff --git a/src/repositories/ApiBasedRepository.ts b/src/repositories/ApiBasedRepository.ts index 4ebf8eb..f83f17c 100644 --- a/src/repositories/ApiBasedRepository.ts +++ b/src/repositories/ApiBasedRepository.ts @@ -305,7 +305,7 @@ ${json}`); public async getStopsBySystemId(systemId: string): Promise { 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) {