mirror of
https://github.com/KevinMidboe/immich.git
synced 2025-12-08 04:09:07 +00:00
fix(server): make system config core singleton (#4392)
* make system config core singleton * refactor * fix tests * chore: fix tests --------- Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
This commit is contained in:
@@ -134,7 +134,7 @@ export enum FeatureFlag {
|
||||
|
||||
export type FeatureFlags = Record<FeatureFlag, boolean>;
|
||||
|
||||
const singleton = new Subject<SystemConfig>();
|
||||
let instance: SystemConfigCore | null;
|
||||
|
||||
@Injectable()
|
||||
export class SystemConfigCore {
|
||||
@@ -142,9 +142,20 @@ export class SystemConfigCore {
|
||||
private validators: SystemConfigValidator[] = [];
|
||||
private configCache: SystemConfig | null = null;
|
||||
|
||||
public config$ = singleton;
|
||||
public config$ = new Subject<SystemConfig>();
|
||||
|
||||
constructor(private repository: ISystemConfigRepository) {}
|
||||
private constructor(private repository: ISystemConfigRepository) {}
|
||||
|
||||
static create(repository: ISystemConfigRepository) {
|
||||
if (!instance) {
|
||||
instance = new SystemConfigCore(repository);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
static reset() {
|
||||
instance = null;
|
||||
}
|
||||
|
||||
async requireFeature(feature: FeatureFlag) {
|
||||
const hasFeature = await this.hasFeature(feature);
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
} from '@app/infra/entities';
|
||||
import { BadRequestException } from '@nestjs/common';
|
||||
import { newCommunicationRepositoryMock, newJobRepositoryMock, newSystemConfigRepositoryMock } from '@test';
|
||||
import { ICommunicationRepository } from '..';
|
||||
import { ICommunicationRepository } from '../communication';
|
||||
import { IJobRepository, JobName, QueueName } from '../job';
|
||||
import { SystemConfigValidator, defaults } from './system-config.core';
|
||||
import { ISystemConfigRepository } from './system-config.repository';
|
||||
|
||||
@@ -24,7 +24,7 @@ export class SystemConfigService {
|
||||
@Inject(ICommunicationRepository) private communicationRepository: ICommunicationRepository,
|
||||
@Inject(IJobRepository) private jobRepository: IJobRepository,
|
||||
) {
|
||||
this.core = new SystemConfigCore(repository);
|
||||
this.core = SystemConfigCore.create(repository);
|
||||
}
|
||||
|
||||
get config$() {
|
||||
|
||||
Reference in New Issue
Block a user