mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-16 23:40:32 +00:00
Switch to using in-memory shuttle and ETA repositories
This is to improve performance until Redis is migrated to the same memory space as the server.
This commit is contained in:
@@ -14,16 +14,11 @@ import {
|
|||||||
ParkingRepositoryLoaderBuilderArguments
|
ParkingRepositoryLoaderBuilderArguments
|
||||||
} from "../loaders/parking/buildParkingRepositoryLoaderIfExists";
|
} from "../loaders/parking/buildParkingRepositoryLoaderIfExists";
|
||||||
import { RedisParkingRepository } from "../repositories/parking/RedisParkingRepository";
|
import { RedisParkingRepository } from "../repositories/parking/RedisParkingRepository";
|
||||||
import { RedisShuttleRepository } from "../repositories/shuttle/RedisShuttleRepository";
|
|
||||||
import { ShuttleGetterRepository } from "../repositories/shuttle/ShuttleGetterRepository";
|
import { ShuttleGetterRepository } from "../repositories/shuttle/ShuttleGetterRepository";
|
||||||
import { InMemoryExternalSourceETARepository } from "../repositories/shuttle/eta/InMemoryExternalSourceETARepository";
|
import { InMemoryExternalSourceETARepository } from "../repositories/shuttle/eta/InMemoryExternalSourceETARepository";
|
||||||
import { ETAGetterRepository } from "../repositories/shuttle/eta/ETAGetterRepository";
|
import { ETAGetterRepository } from "../repositories/shuttle/eta/ETAGetterRepository";
|
||||||
import { RedisSelfUpdatingETARepository } from "../repositories/shuttle/eta/RedisSelfUpdatingETARepository";
|
|
||||||
import { RedisExternalSourceETARepository } from "../repositories/shuttle/eta/RedisExternalSourceETARepository";
|
|
||||||
import { InMemorySelfUpdatingETARepository } from "../repositories/shuttle/eta/InMemorySelfUpdatingETARepository";
|
import { InMemorySelfUpdatingETARepository } from "../repositories/shuttle/eta/InMemorySelfUpdatingETARepository";
|
||||||
import { BaseRedisETARepository } from "../repositories/shuttle/eta/BaseRedisETARepository";
|
|
||||||
import { BaseInMemoryETARepository } from "../repositories/shuttle/eta/BaseInMemoryETARepository";
|
import { BaseInMemoryETARepository } from "../repositories/shuttle/eta/BaseInMemoryETARepository";
|
||||||
import createRedisClientForRepository from "../helpers/createRedisClientForRepository";
|
|
||||||
|
|
||||||
export interface InterchangeSystemBuilderArguments {
|
export interface InterchangeSystemBuilderArguments {
|
||||||
name: string;
|
name: string;
|
||||||
@@ -78,7 +73,7 @@ export class InterchangeSystem {
|
|||||||
static async build(
|
static async build(
|
||||||
args: InterchangeSystemBuilderArguments,
|
args: InterchangeSystemBuilderArguments,
|
||||||
) {
|
) {
|
||||||
const { shuttleRepository, timedShuttleDataLoader, etaRepository } = await InterchangeSystem.buildRedisShuttleLoaderAndRepositories(args);
|
const { shuttleRepository, timedShuttleDataLoader, etaRepository } = await InterchangeSystem.buildProductionShuttleLoaderAndRepositories(args);
|
||||||
timedShuttleDataLoader.start();
|
timedShuttleDataLoader.start();
|
||||||
|
|
||||||
const { notificationScheduler, notificationRepository } = await InterchangeSystem.buildNotificationSchedulerAndRepository(
|
const { notificationScheduler, notificationRepository } = await InterchangeSystem.buildNotificationSchedulerAndRepository(
|
||||||
@@ -104,34 +99,30 @@ export class InterchangeSystem {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async buildRedisShuttleLoaderAndRepositories(args: InterchangeSystemBuilderArguments) {
|
private static async buildProductionShuttleLoaderAndRepositories(args: InterchangeSystemBuilderArguments) {
|
||||||
const shuttleRepository = new RedisShuttleRepository(
|
const shuttleRepository = new UnoptimizedInMemoryShuttleRepository(
|
||||||
createRedisClientForRepository(),
|
|
||||||
args.shuttleStopArrivalDegreeDelta,
|
args.shuttleStopArrivalDegreeDelta,
|
||||||
);
|
);
|
||||||
await shuttleRepository.connect();
|
|
||||||
|
|
||||||
let etaRepository: BaseRedisETARepository;
|
let etaRepository: BaseInMemoryETARepository;
|
||||||
let shuttleDataLoader: ApiBasedShuttleRepositoryLoader;
|
let shuttleDataLoader: ApiBasedShuttleRepositoryLoader;
|
||||||
if (args.useSelfUpdatingEtas) {
|
if (args.useSelfUpdatingEtas) {
|
||||||
etaRepository = new RedisSelfUpdatingETARepository(shuttleRepository);
|
etaRepository = new InMemorySelfUpdatingETARepository(shuttleRepository);
|
||||||
(etaRepository as RedisSelfUpdatingETARepository).startListeningForUpdates();
|
(etaRepository as InMemorySelfUpdatingETARepository).startListeningForUpdates();
|
||||||
shuttleDataLoader = new ApiBasedShuttleRepositoryLoader(
|
shuttleDataLoader = new ApiBasedShuttleRepositoryLoader(
|
||||||
args.passioSystemId,
|
args.passioSystemId,
|
||||||
args.id,
|
args.id,
|
||||||
shuttleRepository,
|
shuttleRepository,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
etaRepository = new RedisExternalSourceETARepository();
|
etaRepository = new InMemoryExternalSourceETARepository();
|
||||||
shuttleDataLoader = new ApiBasedShuttleRepositoryLoader(
|
shuttleDataLoader = new ApiBasedShuttleRepositoryLoader(
|
||||||
args.passioSystemId,
|
args.passioSystemId,
|
||||||
args.id,
|
args.id,
|
||||||
shuttleRepository,
|
shuttleRepository,
|
||||||
etaRepository as RedisExternalSourceETARepository,
|
etaRepository as InMemoryExternalSourceETARepository,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
await etaRepository.connect();
|
|
||||||
|
|
||||||
const timedShuttleDataLoader = new TimedApiBasedRepositoryLoader(
|
const timedShuttleDataLoader = new TimedApiBasedRepositoryLoader(
|
||||||
shuttleDataLoader,
|
shuttleDataLoader,
|
||||||
);
|
);
|
||||||
@@ -191,17 +182,17 @@ export class InterchangeSystem {
|
|||||||
static buildForTesting(
|
static buildForTesting(
|
||||||
args: InterchangeSystemBuilderArguments,
|
args: InterchangeSystemBuilderArguments,
|
||||||
) {
|
) {
|
||||||
const { shuttleRepository, timedShuttleLoader, etaRepository } = InterchangeSystem.buildInMemoryShuttleLoaderAndRepositories(args);
|
const { shuttleRepository, timedShuttleLoader, etaRepository } = InterchangeSystem.buildTestingShuttleLoaderAndRepositories(args);
|
||||||
// Timed shuttle loader is not started here
|
// Timed shuttle loader is not started here
|
||||||
|
|
||||||
const { notificationScheduler, notificationRepository } = InterchangeSystem.buildInMemoryNotificationSchedulerAndRepository(
|
const { notificationScheduler, notificationRepository } = InterchangeSystem.buildTestingNotificationSchedulerAndRepository(
|
||||||
etaRepository,
|
etaRepository,
|
||||||
shuttleRepository,
|
shuttleRepository,
|
||||||
args
|
args
|
||||||
);
|
);
|
||||||
notificationScheduler.startListeningForUpdates();
|
notificationScheduler.startListeningForUpdates();
|
||||||
|
|
||||||
let { parkingRepository, timedParkingLoader } = this.buildInMemoryParkingLoaderAndRepository(args.parkingSystemId);
|
let { parkingRepository, timedParkingLoader } = this.buildTestingParkingLoaderAndRepository(args.parkingSystemId);
|
||||||
// Timed parking loader is not started here
|
// Timed parking loader is not started here
|
||||||
|
|
||||||
return new InterchangeSystem(
|
return new InterchangeSystem(
|
||||||
@@ -217,7 +208,7 @@ export class InterchangeSystem {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static buildInMemoryNotificationSchedulerAndRepository(
|
private static buildTestingNotificationSchedulerAndRepository(
|
||||||
etaRepository: ETAGetterRepository,
|
etaRepository: ETAGetterRepository,
|
||||||
shuttleRepository: UnoptimizedInMemoryShuttleRepository,
|
shuttleRepository: UnoptimizedInMemoryShuttleRepository,
|
||||||
args: InterchangeSystemBuilderArguments
|
args: InterchangeSystemBuilderArguments
|
||||||
@@ -233,7 +224,7 @@ export class InterchangeSystem {
|
|||||||
return { notificationScheduler, notificationRepository };
|
return { notificationScheduler, notificationRepository };
|
||||||
}
|
}
|
||||||
|
|
||||||
private static buildInMemoryParkingLoaderAndRepository(id?: string) {
|
private static buildTestingParkingLoaderAndRepository(id?: string) {
|
||||||
if (id === undefined) {
|
if (id === undefined) {
|
||||||
return { parkingRepository: null, timedParkingLoader: null };
|
return { parkingRepository: null, timedParkingLoader: null };
|
||||||
}
|
}
|
||||||
@@ -256,7 +247,7 @@ export class InterchangeSystem {
|
|||||||
return { parkingRepository, timedParkingLoader };
|
return { parkingRepository, timedParkingLoader };
|
||||||
}
|
}
|
||||||
|
|
||||||
private static buildInMemoryShuttleLoaderAndRepositories(args: InterchangeSystemBuilderArguments) {
|
private static buildTestingShuttleLoaderAndRepositories(args: InterchangeSystemBuilderArguments) {
|
||||||
const shuttleRepository = new UnoptimizedInMemoryShuttleRepository(
|
const shuttleRepository = new UnoptimizedInMemoryShuttleRepository(
|
||||||
args.shuttleStopArrivalDegreeDelta,
|
args.shuttleStopArrivalDegreeDelta,
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user