mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
fix logic for getting stop data
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user