1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-23 19:53:43 +00:00

Remove StateService useAccountCache (#8882)

* Remove Account Cache from StateService

* Remove Extra Change

* Fix Desktop Build
This commit is contained in:
Justin Baur
2024-04-24 11:20:13 -04:00
committed by GitHub
parent b7957d6e28
commit 94fe9bd053
10 changed files with 0 additions and 95 deletions

View File

@@ -36,7 +36,6 @@ export const MEMORY_STORAGE = new SafeInjectionToken<AbstractMemoryStorageServic
);
export const SECURE_STORAGE = new SafeInjectionToken<AbstractStorageService>("SECURE_STORAGE");
export const STATE_FACTORY = new SafeInjectionToken<StateFactory>("STATE_FACTORY");
export const STATE_SERVICE_USE_CACHE = new SafeInjectionToken<boolean>("STATE_SERVICE_USE_CACHE");
export const LOGOUT_CALLBACK = new SafeInjectionToken<
(expired: boolean, userId?: string) => Promise<void>
>("LOGOUT_CALLBACK");

View File

@@ -269,7 +269,6 @@ import {
SafeInjectionToken,
SECURE_STORAGE,
STATE_FACTORY,
STATE_SERVICE_USE_CACHE,
SUPPORTS_SECURE_STORAGE,
SYSTEM_LANGUAGE,
SYSTEM_THEME_OBSERVABLE,
@@ -313,10 +312,6 @@ const safeProviders: SafeProvider[] = [
provide: STATE_FACTORY,
useValue: new StateFactory(GlobalState, Account),
}),
safeProvider({
provide: STATE_SERVICE_USE_CACHE,
useValue: true,
}),
safeProvider({
provide: LOGOUT_CALLBACK,
useFactory:
@@ -690,7 +685,6 @@ const safeProviders: SafeProvider[] = [
EnvironmentService,
TokenServiceAbstraction,
MigrationRunner,
STATE_SERVICE_USE_CACHE,
],
}),
safeProvider({

View File

@@ -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>(