1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 08:43:33 +00:00

Special Case 0 to mean no caching at all (#10221)

This commit is contained in:
Justin Baur
2024-07-23 07:58:59 -04:00
committed by GitHub
parent 2ea2045686
commit 477294379b
5 changed files with 37 additions and 12 deletions

View File

@@ -100,6 +100,24 @@ describe("DefaultSingleUserState", () => {
);
expect(state).toBeTruthy();
});
it("should go to disk each subscription if a cleanupDelayMs of 0 is given", async () => {
const state = new DefaultSingleUserState(
userId,
new UserKeyDefinition(testStateDefinition, "test", {
cleanupDelayMs: 0,
deserializer: TestState.fromJSON,
clearOn: [],
}),
diskStorageService,
stateEventRegistrarService,
);
await firstValueFrom(state.state$);
await firstValueFrom(state.state$);
expect(diskStorageService.mock.get).toHaveBeenCalledTimes(2);
});
});
describe("combinedState$", () => {

View File

@@ -48,15 +48,22 @@ export abstract class StateBase<T, KeyDef extends KeyDefinitionRequirements<T>>
}),
);
this.state$ = merge(
let state$ = merge(
defer(() => getStoredValue(key, storageService, keyDefinition.deserializer)),
storageUpdate$,
).pipe(
share({
connector: () => new ReplaySubject(1),
resetOnRefCountZero: () => timer(keyDefinition.cleanupDelayMs),
}),
);
// If 0 cleanup is chosen, treat this as absolutely no cache
if (keyDefinition.cleanupDelayMs !== 0) {
state$ = state$.pipe(
share({
connector: () => new ReplaySubject(1),
resetOnRefCountZero: () => timer(keyDefinition.cleanupDelayMs),
}),
);
}
this.state$ = state$;
}
async update<TCombine>(