From f06e778b80a723cb2260b0f766bf4491626e84c6 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Fri, 14 Nov 2025 10:26:52 -0800 Subject: [PATCH] Implement removal of last stop data on shuttle removal --- src/repositories/shuttle/RedisShuttleRepository.ts | 14 +++++++++++++- .../UnoptimizedInMemoryShuttleRepository.ts | 5 +++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/repositories/shuttle/RedisShuttleRepository.ts b/src/repositories/shuttle/RedisShuttleRepository.ts index 1a6b4d0..763dde5 100644 --- a/src/repositories/shuttle/RedisShuttleRepository.ts +++ b/src/repositories/shuttle/RedisShuttleRepository.ts @@ -534,6 +534,9 @@ export class RedisShuttleRepository extends BaseRedisRepository implements Shutt const key = this.createShuttleKey(shuttleId); await this.redisClient.del(key); this.emit(ShuttleRepositoryEvent.SHUTTLE_REMOVED, shuttle); + + await this.removeShuttleLastStopIfExists(shuttleId); + return shuttle; } return null; @@ -559,6 +562,15 @@ export class RedisShuttleRepository extends BaseRedisRepository implements Shutt return null; } + private async removeShuttleLastStopIfExists(shuttleId: string) { + const lastStop = await this.getShuttleLastStopArrival(shuttleId); + if (lastStop) { + const key = this.createShuttleLastStopKey(shuttleId); + await this.redisClient.del(key); + return lastStop; + } + return null; + } // Clear methods public async clearShuttleData(): Promise { @@ -589,7 +601,7 @@ export class RedisShuttleRepository extends BaseRedisRepository implements Shutt await this.redisClient.del(keys); } } - + private async clearShuttleLastStopData(): Promise { const keys = await this.redisClient.keys('shuttle:laststop:*'); if (keys.length > 0) { diff --git a/src/repositories/shuttle/UnoptimizedInMemoryShuttleRepository.ts b/src/repositories/shuttle/UnoptimizedInMemoryShuttleRepository.ts index 8b7a3d5..a3e7dac 100644 --- a/src/repositories/shuttle/UnoptimizedInMemoryShuttleRepository.ts +++ b/src/repositories/shuttle/UnoptimizedInMemoryShuttleRepository.ts @@ -267,6 +267,7 @@ export class UnoptimizedInMemoryShuttleRepository const shuttle = await this.removeEntityByIdIfExists(shuttleId, this.shuttles); if (shuttle != null) { this.emit(ShuttleRepositoryEvent.SHUTTLE_REMOVED, shuttle); + await this.removeShuttleLastStopIfExists(shuttleId); } return shuttle; } @@ -282,6 +283,10 @@ export class UnoptimizedInMemoryShuttleRepository }, this.orderedStops); } + private async removeShuttleLastStopIfExists(shuttleId: string) { + this.shuttleLastStopArrivals.delete(shuttleId); + } + public async clearShuttleData(): Promise { this.shuttles = []; await this.clearShuttleLastStopData();