1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 15:53:27 +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) {

View File

@@ -4,7 +4,6 @@ import { Subject, merge } from "rxjs";
import { SafeProvider, safeProvider } from "@bitwarden/angular/platform/utils/safe-provider";
import {
SECURE_STORAGE,
STATE_SERVICE_USE_CACHE,
LOCALES_DIRECTORY,
SYSTEM_LANGUAGE,
MEMORY_STORAGE,
@@ -205,7 +204,6 @@ const safeProviders: SafeProvider[] = [
EnvironmentService,
TokenService,
MigrationRunner,
STATE_SERVICE_USE_CACHE,
],
}),
safeProvider({

View File

@@ -205,7 +205,6 @@ export class Main {
this.environmentService,
this.tokenService,
this.migrationRunner,
false, // Do not use disk caching because this will get out of sync with the renderer service
);
this.desktopSettingsService = new DesktopSettingsService(stateProvider);

View File

@@ -5,7 +5,6 @@ import { SafeProvider, safeProvider } from "@bitwarden/angular/platform/utils/sa
import {
SECURE_STORAGE,
STATE_FACTORY,
STATE_SERVICE_USE_CACHE,
LOCALES_DIRECTORY,
SYSTEM_LANGUAGE,
MEMORY_STORAGE,
@@ -78,10 +77,6 @@ const safeProviders: SafeProvider[] = [
provide: STATE_FACTORY,
useValue: new StateFactory(GlobalState, Account),
}),
safeProvider({
provide: STATE_SERVICE_USE_CACHE,
useValue: false,
}),
safeProvider({
provide: I18nServiceAbstraction,
useClass: I18nService,

View File

@@ -4,7 +4,6 @@ import {
MEMORY_STORAGE,
SECURE_STORAGE,
STATE_FACTORY,
STATE_SERVICE_USE_CACHE,
} from "@bitwarden/angular/services/injection-tokens";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { TokenService } from "@bitwarden/common/auth/abstractions/token.service";
@@ -34,7 +33,6 @@ export class StateService extends BaseStateService<GlobalState, Account> {
environmentService: EnvironmentService,
tokenService: TokenService,
migrationRunner: MigrationRunner,
@Inject(STATE_SERVICE_USE_CACHE) useAccountCache = true,
) {
super(
storageService,
@@ -46,7 +44,6 @@ export class StateService extends BaseStateService<GlobalState, Account> {
environmentService,
tokenService,
migrationRunner,
useAccountCache,
);
}