diff --git a/server/src/domain/metadata/metadata.service.spec.ts b/server/src/domain/metadata/metadata.service.spec.ts index e6ca7f199c..f31605b121 100644 --- a/server/src/domain/metadata/metadata.service.spec.ts +++ b/server/src/domain/metadata/metadata.service.spec.ts @@ -67,6 +67,10 @@ describe(MetadataService.name, () => { ); }); + afterEach(async () => { + await sut.teardown(); + }); + it('should be defined', () => { expect(sut).toBeDefined(); }); diff --git a/server/src/domain/metadata/metadata.service.ts b/server/src/domain/metadata/metadata.service.ts index 8829f6c6f4..45193c2e10 100644 --- a/server/src/domain/metadata/metadata.service.ts +++ b/server/src/domain/metadata/metadata.service.ts @@ -4,6 +4,7 @@ import { ExifDateTime, Tags } from 'exiftool-vendored'; import { firstDateTime } from 'exiftool-vendored/dist/FirstDateTime'; import { constants } from 'fs/promises'; import { Duration } from 'luxon'; +import { Subscription } from 'rxjs'; import { usePagination } from '../domain.util'; import { IBaseJob, IEntityJob, JOBS_ASSET_PAGINATION_SIZE, JobName, QueueName } from '../job'; import { @@ -67,6 +68,7 @@ export class MetadataService { private storageCore: StorageCore; private configCore: SystemConfigCore; private oldCities?: string; + private subscription: Subscription | null = null; constructor( @Inject(IAlbumRepository) private albumRepository: IAlbumRepository, @@ -81,10 +83,13 @@ export class MetadataService { ) { this.configCore = SystemConfigCore.create(configRepository); this.storageCore = StorageCore.create(assetRepository, moveRepository, personRepository, storageRepository); - this.configCore.config$.subscribe(() => this.init()); } async init(deleteCache = false) { + if (!this.subscription) { + this.subscription = this.configCore.config$.subscribe(() => this.init()); + } + const { reverseGeocoding } = await this.configCore.getConfig(); const { citiesFileOverride } = reverseGeocoding; @@ -111,6 +116,7 @@ export class MetadataService { } async teardown() { + this.subscription?.unsubscribe(); await this.repository.teardown(); } diff --git a/server/src/infra/repositories/communication.repository.ts b/server/src/infra/repositories/communication.repository.ts index 908044f40e..e1bbc77de9 100644 --- a/server/src/infra/repositories/communication.repository.ts +++ b/server/src/infra/repositories/communication.repository.ts @@ -10,7 +10,7 @@ export class CommunicationRepository implements OnGatewayConnection, OnGatewayDi constructor(private authService: AuthService) {} - @WebSocketServer() server!: Server; + @WebSocketServer() server?: Server; addEventListener(event: 'connect', callback: Callback) { this.onConnectCallbacks.push(callback); @@ -37,10 +37,10 @@ export class CommunicationRepository implements OnGatewayConnection, OnGatewayDi } send(event: CommunicationEvent, userId: string, data: any) { - this.server.to(userId).emit(event, data); + this.server?.to(userId).emit(event, data); } broadcast(event: CommunicationEvent, data: any) { - this.server.emit(event, data); + this.server?.emit(event, data); } }