mirror of
https://github.com/bitwarden/browser
synced 2025-12-14 23:33:31 +00:00
Remove StateService useAccountCache (#8882)
* Remove Account Cache from StateService * Remove Extra Change * Fix Desktop Build
This commit is contained in:
@@ -65,8 +65,6 @@ export class StateService<
|
||||
private hasBeenInited = false;
|
||||
protected isRecoveredSession = false;
|
||||
|
||||
protected accountDiskCache = new BehaviorSubject<Record<string, TAccount>>({});
|
||||
|
||||
// default account serializer, must be overridden by child class
|
||||
protected accountDeserializer = Account.fromJSON as (json: Jsonify<TAccount>) => TAccount;
|
||||
|
||||
@@ -80,7 +78,6 @@ export class StateService<
|
||||
protected environmentService: EnvironmentService,
|
||||
protected tokenService: TokenService,
|
||||
private migrationRunner: MigrationRunner,
|
||||
protected useAccountCache: boolean = true,
|
||||
) {}
|
||||
|
||||
async init(initOptions: InitOptions = {}): Promise<void> {
|
||||
@@ -995,13 +992,6 @@ export class StateService<
|
||||
return null;
|
||||
}
|
||||
|
||||
if (this.useAccountCache) {
|
||||
const cachedAccount = this.accountDiskCache.value[options.userId];
|
||||
if (cachedAccount != null) {
|
||||
return cachedAccount;
|
||||
}
|
||||
}
|
||||
|
||||
const account = options?.useSecureStorage
|
||||
? (await this.secureStorageService.get<TAccount>(options.userId, options)) ??
|
||||
(await this.storageService.get<TAccount>(
|
||||
@@ -1009,8 +999,6 @@ export class StateService<
|
||||
this.reconcileOptions(options, { htmlStorageLocation: HtmlStorageLocation.Local }),
|
||||
))
|
||||
: await this.storageService.get<TAccount>(options.userId, options);
|
||||
|
||||
this.setDiskCache(options.userId, account);
|
||||
return account;
|
||||
}
|
||||
|
||||
@@ -1040,8 +1028,6 @@ export class StateService<
|
||||
: this.storageService;
|
||||
|
||||
await storageLocation.save(`${options.userId}`, account, options);
|
||||
|
||||
this.deleteDiskCache(options.userId);
|
||||
}
|
||||
|
||||
protected async saveAccountToMemory(account: TAccount): Promise<void> {
|
||||
@@ -1241,9 +1227,6 @@ export class StateService<
|
||||
await this.updateState(async (state) => {
|
||||
userId = userId ?? state.activeUserId;
|
||||
delete state.accounts[userId];
|
||||
|
||||
this.deleteDiskCache(userId);
|
||||
|
||||
return state;
|
||||
});
|
||||
}
|
||||
@@ -1357,20 +1340,6 @@ export class StateService<
|
||||
return await this.setState(updatedState);
|
||||
});
|
||||
}
|
||||
|
||||
private setDiskCache(key: string, value: TAccount, options?: StorageOptions) {
|
||||
if (this.useAccountCache) {
|
||||
this.accountDiskCache.value[key] = value;
|
||||
this.accountDiskCache.next(this.accountDiskCache.value);
|
||||
}
|
||||
}
|
||||
|
||||
protected deleteDiskCache(key: string) {
|
||||
if (this.useAccountCache) {
|
||||
delete this.accountDiskCache.value[key];
|
||||
this.accountDiskCache.next(this.accountDiskCache.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function withPrototypeForArrayMembers<T>(
|
||||
|
||||
Reference in New Issue
Block a user