refactor: config caching (#10168)

This commit is contained in:
Jason Rasmussen 2024-06-12 07:07:35 -04:00 committed by GitHub
parent 5dda5d93f5
commit e84657192c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 54 additions and 54 deletions

View file

@ -254,7 +254,7 @@ export class StorageCore {
this.logger.warn(`Unable to complete move. File size mismatch: ${newPathSize} !== ${oldPathSize}`);
return false;
}
const config = await this.configCore.getConfig();
const config = await this.configCore.getConfig({ withCache: true });
if (assetInfo && config.storageTemplate.hashVerificationEnabled) {
const { checksum } = assetInfo;
const newChecksum = await this.cryptoRepository.hashFile(newPath);

View file

@ -42,8 +42,8 @@ export class SystemConfigCore {
instance = null;
}
async getConfig(force = false): Promise<SystemConfig> {
if (force || !this.config) {
async getConfig({ withCache }: { withCache: boolean }): Promise<SystemConfig> {
if (!withCache || !this.config) {
const lastUpdated = this.lastUpdated;
await this.asyncLock.acquire(DatabaseLock[DatabaseLock.GetSystemConfig], async () => {
if (lastUpdated === this.lastUpdated) {
@ -74,13 +74,13 @@ export class SystemConfigCore {
await this.repository.set(SystemMetadataKey.SYSTEM_CONFIG, partialConfig);
const config = await this.getConfig(true);
const config = await this.getConfig({ withCache: false });
this.config$.next(config);
return config;
}
async refreshConfig() {
const newConfig = await this.getConfig(true);
const newConfig = await this.getConfig({ withCache: false });
this.config$.next(newConfig);
}