From 91d020a7bc4fd4df7e27cf9665e6db753adecb1d Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Wed, 8 Jan 2025 17:18:12 -0800 Subject: [PATCH] update caching behavior temporarily for updateEtasForSystemIfTTL --- src/repositories/ApiBasedRepository.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/repositories/ApiBasedRepository.ts b/src/repositories/ApiBasedRepository.ts index a2571f8..3876eef 100644 --- a/src/repositories/ApiBasedRepository.ts +++ b/src/repositories/ApiBasedRepository.ts @@ -5,7 +5,8 @@ const baseUrl = "https://passiogo.com/mapGetData.php" // TODO: add TTL values to everything // TODO: remove RepositoryDataLoader and UnoptimizedInMemoryRepository -// TODO: make milleseconds (TTL) required on everything +// TODO: make milliseconds (TTL) required on everything +// TODO: extract cache into its own class export interface ApiBasedRepositoryCache { etasForShuttleId?: { @@ -138,6 +139,14 @@ export class ApiBasedRepository implements GetterRepository { const json = await response.json(); if (json.ETAs && json.ETAs[stop.id]) { + if (!this.cache.etasForStopId) { + this.cache.etasForStopId = {}; + } + this.cache.etasForStopId[stop.id] = []; + + // TODO: restore normal cache behavior + this.cache.etasForShuttleId = {}; + // Continue with the parsing json.ETAs[stop.id].forEach((jsonEta: any) => { // Update cache @@ -151,10 +160,6 @@ export class ApiBasedRepository implements GetterRepository { // TODO: create cache abstraction to deal with possibly undefined properties - if (!this.cache.etasForStopId[stop.id]) { - this.cache.etasForStopId[stop.id] = [] - } - const shuttleId: string = jsonEta.busId; if (!this.cache.etasForShuttleId[shuttleId]) { this.cache.etasForShuttleId[shuttleId] = [];