update caching behavior temporarily for updateEtasForSystemIfTTL

This commit is contained in:
2025-01-08 17:18:12 -08:00
parent 9d5d499fb6
commit 91d020a7bc

View File

@@ -5,7 +5,8 @@ const baseUrl = "https://passiogo.com/mapGetData.php"
// TODO: add TTL values to everything // TODO: add TTL values to everything
// TODO: remove RepositoryDataLoader and UnoptimizedInMemoryRepository // 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 { export interface ApiBasedRepositoryCache {
etasForShuttleId?: { etasForShuttleId?: {
@@ -138,6 +139,14 @@ export class ApiBasedRepository implements GetterRepository {
const json = await response.json(); const json = await response.json();
if (json.ETAs && json.ETAs[stop.id]) { 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 // Continue with the parsing
json.ETAs[stop.id].forEach((jsonEta: any) => { json.ETAs[stop.id].forEach((jsonEta: any) => {
// Update cache // Update cache
@@ -151,10 +160,6 @@ export class ApiBasedRepository implements GetterRepository {
// TODO: create cache abstraction to deal with possibly undefined properties // 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; const shuttleId: string = jsonEta.busId;
if (!this.cache.etasForShuttleId[shuttleId]) { if (!this.cache.etasForShuttleId[shuttleId]) {
this.cache.etasForShuttleId[shuttleId] = []; this.cache.etasForShuttleId[shuttleId] = [];