1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-27 13:43:41 +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

@@ -30,7 +30,6 @@ import {
type StateServiceFactoryOptions = FactoryOptions & {
stateServiceOptions: {
useAccountCache?: boolean;
stateFactory: StateFactory<GlobalState, Account>;
};
};
@@ -64,7 +63,6 @@ export async function stateServiceFactory(
await environmentServiceFactory(cache, opts),
await tokenServiceFactory(cache, opts),
await migrationRunnerFactory(cache, opts),
opts.stateServiceOptions.useAccountCache,
),
);
// TODO: If we run migration through a chrome installed/updated event we can turn off running migrations

View File

@@ -27,7 +27,6 @@ describe("Browser State Service", () => {
let diskStorageService: MockProxy<AbstractStorageService>;
let logService: MockProxy<LogService>;
let stateFactory: MockProxy<StateFactory<GlobalState, Account>>;
let useAccountCache: boolean;
let environmentService: MockProxy<EnvironmentService>;
let tokenService: MockProxy<TokenService>;
let migrationRunner: MockProxy<MigrationRunner>;
@@ -46,8 +45,6 @@ describe("Browser State Service", () => {
environmentService = mock();
tokenService = mock();
migrationRunner = mock();
// turn off account cache for tests
useAccountCache = false;
state = new State(new GlobalState());
state.accounts[userId] = new Account({
@@ -78,7 +75,6 @@ describe("Browser State Service", () => {
environmentService,
tokenService,
migrationRunner,
useAccountCache,
);
});

View File

@@ -15,7 +15,6 @@ import { MigrationRunner } from "@bitwarden/common/platform/services/migration-r
import { StateService as BaseStateService } from "@bitwarden/common/platform/services/state.service";
import { Account } from "../../models/account";
import { BrowserApi } from "../browser/browser-api";
import { browserSession, sessionSync } from "../decorators/session-sync-observable";
import { BrowserStateService } from "./abstractions/browser-state.service";
@@ -45,7 +44,6 @@ export class DefaultBrowserStateService
environmentService: EnvironmentService,
tokenService: TokenService,
migrationRunner: MigrationRunner,
useAccountCache = true,
) {
super(
storageService,
@@ -57,45 +55,7 @@ export class DefaultBrowserStateService
environmentService,
tokenService,
migrationRunner,
useAccountCache,
);
// TODO: This is a hack to fix having a disk cache on both the popup and
// the background page that can get out of sync. We need to work out the
// best way to handle caching with multiple instances of the state service.
if (useAccountCache) {
BrowserApi.storageChangeListener((changes, namespace) => {
if (namespace === "local") {
for (const key of Object.keys(changes)) {
if (key !== "accountActivity" && this.accountDiskCache.value[key]) {
this.deleteDiskCache(key);
}
}
}
});
BrowserApi.addListener(
chrome.runtime.onMessage,
(message: { command: string }, _, respond) => {
if (message.command === "initializeDiskCache") {
respond(JSON.stringify(this.accountDiskCache.value));
}
},
);
}
}
override async initAccountState(): Promise<void> {
if (this.isRecoveredSession && this.useAccountCache) {
// request cache initialization
const response = await BrowserApi.sendMessageWithResponse<string>("initializeDiskCache");
this.accountDiskCache.next(JSON.parse(response));
return;
}
await super.initAccountState();
}
async addAccount(account: Account) {