mirror of
https://github.com/bitwarden/browser
synced 2025-12-20 02:03:39 +00:00
share disk cache to fix syncing issues between contexts
This commit is contained in:
@@ -37,6 +37,7 @@ export abstract class StateService<T extends Account = Account> {
|
||||
accounts$: Observable<{ [userId: string]: T }>;
|
||||
activeAccount$: Observable<string>;
|
||||
activeAccountUnlocked$: Observable<boolean>;
|
||||
accountDiskCache$: Observable<Record<string, T>>;
|
||||
|
||||
addAccount: (account: T) => Promise<void>;
|
||||
setActiveUser: (userId: string) => Promise<void>;
|
||||
|
||||
@@ -95,7 +95,8 @@ export class StateService<
|
||||
private hasBeenInited = false;
|
||||
private isRecoveredSession = false;
|
||||
|
||||
protected accountDiskCache = new BehaviorSubject<Record<string, TAccount>>({});
|
||||
protected accountDiskCacheSubject = new BehaviorSubject<Record<string, TAccount>>({});
|
||||
accountDiskCache$ = this.accountDiskCacheSubject.asObservable();
|
||||
|
||||
// default account serializer, must be overridden by child class
|
||||
protected accountDeserializer = Account.fromJSON as (json: Jsonify<TAccount>) => TAccount;
|
||||
@@ -2770,7 +2771,7 @@ export class StateService<
|
||||
}
|
||||
|
||||
if (this.useAccountCache) {
|
||||
const cachedAccount = this.accountDiskCache.value[options.userId];
|
||||
const cachedAccount = this.accountDiskCacheSubject.value[options.userId];
|
||||
if (cachedAccount != null) {
|
||||
return cachedAccount;
|
||||
}
|
||||
@@ -3166,15 +3167,15 @@ export class StateService<
|
||||
|
||||
private setDiskCache(key: string, value: TAccount, options?: StorageOptions) {
|
||||
if (this.useAccountCache) {
|
||||
this.accountDiskCache.value[key] = value;
|
||||
this.accountDiskCache.next(this.accountDiskCache.value);
|
||||
this.accountDiskCacheSubject.value[key] = value;
|
||||
this.accountDiskCacheSubject.next(this.accountDiskCacheSubject.value);
|
||||
}
|
||||
}
|
||||
|
||||
private deleteDiskCache(key: string) {
|
||||
if (this.useAccountCache) {
|
||||
delete this.accountDiskCache.value[key];
|
||||
this.accountDiskCache.next(this.accountDiskCache.value);
|
||||
delete this.accountDiskCacheSubject.value[key];
|
||||
this.accountDiskCacheSubject.next(this.accountDiskCacheSubject.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user