Implement removal of last stop data on shuttle removal

This commit is contained in:
2025-11-14 10:26:52 -08:00
parent 1511b3c118
commit f06e778b80
2 changed files with 18 additions and 1 deletions

View File

@@ -534,6 +534,9 @@ export class RedisShuttleRepository extends BaseRedisRepository implements Shutt
const key = this.createShuttleKey(shuttleId); const key = this.createShuttleKey(shuttleId);
await this.redisClient.del(key); await this.redisClient.del(key);
this.emit(ShuttleRepositoryEvent.SHUTTLE_REMOVED, shuttle); this.emit(ShuttleRepositoryEvent.SHUTTLE_REMOVED, shuttle);
await this.removeShuttleLastStopIfExists(shuttleId);
return shuttle; return shuttle;
} }
return null; return null;
@@ -559,6 +562,15 @@ export class RedisShuttleRepository extends BaseRedisRepository implements Shutt
return null; 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 // Clear methods
public async clearShuttleData(): Promise<void> { public async clearShuttleData(): Promise<void> {

View File

@@ -267,6 +267,7 @@ export class UnoptimizedInMemoryShuttleRepository
const shuttle = await this.removeEntityByIdIfExists(shuttleId, this.shuttles); const shuttle = await this.removeEntityByIdIfExists(shuttleId, this.shuttles);
if (shuttle != null) { if (shuttle != null) {
this.emit(ShuttleRepositoryEvent.SHUTTLE_REMOVED, shuttle); this.emit(ShuttleRepositoryEvent.SHUTTLE_REMOVED, shuttle);
await this.removeShuttleLastStopIfExists(shuttleId);
} }
return shuttle; return shuttle;
} }
@@ -282,6 +283,10 @@ export class UnoptimizedInMemoryShuttleRepository
}, this.orderedStops); }, this.orderedStops);
} }
private async removeShuttleLastStopIfExists(shuttleId: string) {
this.shuttleLastStopArrivals.delete(shuttleId);
}
public async clearShuttleData(): Promise<void> { public async clearShuttleData(): Promise<void> {
this.shuttles = []; this.shuttles = [];
await this.clearShuttleLastStopData(); await this.clearShuttleLastStopData();