From 240fc154ab00a57829d0ce1398a6a6ce93395070 Mon Sep 17 00:00:00 2001 From: Addison Beck Date: Mon, 14 Feb 2022 11:47:01 -0500 Subject: [PATCH] [bug] Allow for toggling the account cache (#674) * [bug] Allow for toggling the account cache * Add missing conditional * Ran prettier --- common/src/services/state.service.ts | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/common/src/services/state.service.ts b/common/src/services/state.service.ts index 9ae48427c6..934f40a9e1 100644 --- a/common/src/services/state.service.ts +++ b/common/src/services/state.service.ts @@ -76,7 +76,8 @@ export class StateService< protected secureStorageService: StorageService, protected logService: LogService, protected stateMigrationService: StateMigrationService, - protected stateFactory: StateFactory + protected stateFactory: StateFactory, + protected useAccountCache: boolean = true ) { this.accountDiskCache = new Map(); } @@ -2163,9 +2164,11 @@ export class StateService< return null; } - const cachedAccount = this.accountDiskCache.get(options.userId); - if (cachedAccount != null) { - return cachedAccount; + if (this.useAccountCache) { + const cachedAccount = this.accountDiskCache.get(options.userId); + if (cachedAccount != null) { + return cachedAccount; + } } const account = options?.useSecureStorage @@ -2176,7 +2179,9 @@ export class StateService< )) : await this.storageService.get(options.userId, options); - this.accountDiskCache.set(options.userId, account); + if (this.useAccountCache) { + this.accountDiskCache.set(options.userId, account); + } return account; } @@ -2206,7 +2211,10 @@ export class StateService< : this.storageService; await storageLocation.save(`${options.userId}`, account, options); - this.accountDiskCache.delete(options.userId); + + if (this.useAccountCache) { + this.accountDiskCache.delete(options.userId); + } } protected async saveAccountToMemory(account: TAccount): Promise { @@ -2407,7 +2415,9 @@ export class StateService< protected removeAccountFromMemory(userId: string = this.state.activeUserId): void { delete this.state.accounts[userId]; - this.accountDiskCache.delete(userId); + if (this.useAccountCache) { + this.accountDiskCache.delete(userId); + } } protected async pruneInMemoryAccounts() {