1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 00:03:56 +00:00

Only sync if synced value changes

Co-authored-by: Daniel James Smith <djsmith85@users.noreply.github.com>
This commit is contained in:
Matt Gibson
2022-12-15 10:12:34 -05:00
parent d8a121463e
commit 024fe226d9
3 changed files with 25 additions and 5 deletions

View File

@@ -1,3 +1,4 @@
import * as objectHash from "object-hash";
import { BehaviorSubject, concatMap, ReplaySubject, Subject, Subscription } from "rxjs";
import { Utils } from "@bitwarden/common/misc/utils";
@@ -10,6 +11,7 @@ import { SyncedItemMetadata } from "./sync-item-metadata";
export class SessionSyncer {
subscription: Subscription;
id = Utils.newGuid();
lastHash: string;
// ignore initial values
private ignoreNUpdates = 0;
@@ -92,8 +94,12 @@ export class SessionSyncer {
}
private async updateSession(value: any) {
await this.stateService.setInSessionMemory(this.metaData.sessionKey, value);
await BrowserApi.sendMessage(this.updateMessageCommand, { id: this.id });
const thisHash = objectHash(value);
if (thisHash !== this.lastHash) {
this.lastHash = thisHash;
await this.stateService.setInSessionMemory(this.metaData.sessionKey, value);
await BrowserApi.sendMessage(this.updateMessageCommand, { id: this.id });
}
}
private get updateMessageCommand() {