refactor(server): events (#13003)

* refactor(server): events

* chore: better type

---------

Co-authored-by: Daniel Dietzler <mail@ddietzler.dev>
This commit is contained in:
Jason Rasmussen 2024-09-30 10:35:11 -04:00 committed by GitHub
parent 95c67949f7
commit a2d457b01d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 260 additions and 259 deletions

View file

@ -4,7 +4,6 @@ import { plainToInstance } from 'class-transformer';
import { validate } from 'class-validator';
import { load as loadYaml } from 'js-yaml';
import * as _ from 'lodash';
import { Subject } from 'rxjs';
import { SystemConfig, defaults } from 'src/config';
import { SystemConfigDto } from 'src/dtos/system-config.dto';
import { SystemMetadataKey } from 'src/enum';
@ -24,8 +23,6 @@ export class SystemConfigCore {
private config: SystemConfig | null = null;
private lastUpdated: number | null = null;
config$ = new Subject<SystemConfig>();
private constructor(
private repository: ISystemMetadataRepository,
private logger: ILoggerRepository,
@ -42,6 +39,11 @@ export class SystemConfigCore {
instance = null;
}
invalidateCache() {
this.config = null;
this.lastUpdated = null;
}
async getConfig({ withCache }: { withCache: boolean }): Promise<SystemConfig> {
if (!withCache || !this.config) {
const lastUpdated = this.lastUpdated;
@ -74,14 +76,7 @@ export class SystemConfigCore {
await this.repository.set(SystemMetadataKey.SYSTEM_CONFIG, partialConfig);
const config = await this.getConfig({ withCache: false });
this.config$.next(config);
return config;
}
async refreshConfig() {
const newConfig = await this.getConfig({ withCache: false });
this.config$.next(newConfig);
return this.getConfig({ withCache: false });
}
isUsingConfigFile() {