Only sync if synced value changes
Co-authored-by: Daniel James Smith <djsmith85@users.noreply.github.com>
This commit is contained in:
parent
d8a121463e
commit
024fe226d9
|
@ -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() {
|
||||
|
|
|
@ -54,6 +54,7 @@
|
|||
"node-fetch": "^2.6.7",
|
||||
"node-forge": "^1.3.1",
|
||||
"nord": "0.2.1",
|
||||
"object-hash": "^3.0.0",
|
||||
"open": "^8.4.0",
|
||||
"papaparse": "^5.3.2",
|
||||
"popper.js": "^1.16.1",
|
||||
|
@ -99,6 +100,7 @@
|
|||
"@types/node-fetch": "^2.6.1",
|
||||
"@types/node-forge": "^1.0.2",
|
||||
"@types/node-ipc": "^9.2.0",
|
||||
"@types/object-hash": "^3.0.1",
|
||||
"@types/papaparse": "^5.3.2",
|
||||
"@types/proper-lockfile": "^4.1.2",
|
||||
"@types/retry": "^0.12.2",
|
||||
|
@ -13024,6 +13026,12 @@
|
|||
"integrity": "sha512-WKG4gTr8przEZBiJ5r3s8ZIAoMXNbOgQ+j/d5O4X3x6kZJRLNvyUJuUK/KoG3+8BaOHPhp2m7WC6JKKeovDSzQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/object-hash": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/object-hash/-/object-hash-3.0.1.tgz",
|
||||
"integrity": "sha512-AeyooJR4pesRnPLXONFEpxrdvwYVkBiq26j4Uo4QYcJO2FQhAFmHHWBfRpEzwMtItz7q9JiD50s7HDbHS7PleQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/papaparse": {
|
||||
"version": "5.3.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/papaparse/-/papaparse-5.3.2.tgz",
|
||||
|
@ -32944,7 +32952,6 @@
|
|||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/object-hash/-/object-hash-3.0.0.tgz",
|
||||
"integrity": "sha512-RSn9F68PjH9HqtltsSnqYC1XXoWe9Bju5+213R98cNGttag9q9yAOTzdbsqvIa7aNm5WffBZFpWYr2aWrklWAw==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">= 6"
|
||||
}
|
||||
|
@ -52966,6 +52973,12 @@
|
|||
"integrity": "sha512-WKG4gTr8przEZBiJ5r3s8ZIAoMXNbOgQ+j/d5O4X3x6kZJRLNvyUJuUK/KoG3+8BaOHPhp2m7WC6JKKeovDSzQ==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/object-hash": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/object-hash/-/object-hash-3.0.1.tgz",
|
||||
"integrity": "sha512-AeyooJR4pesRnPLXONFEpxrdvwYVkBiq26j4Uo4QYcJO2FQhAFmHHWBfRpEzwMtItz7q9JiD50s7HDbHS7PleQ==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/papaparse": {
|
||||
"version": "5.3.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/papaparse/-/papaparse-5.3.2.tgz",
|
||||
|
@ -68490,8 +68503,7 @@
|
|||
"object-hash": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/object-hash/-/object-hash-3.0.0.tgz",
|
||||
"integrity": "sha512-RSn9F68PjH9HqtltsSnqYC1XXoWe9Bju5+213R98cNGttag9q9yAOTzdbsqvIa7aNm5WffBZFpWYr2aWrklWAw==",
|
||||
"dev": true
|
||||
"integrity": "sha512-RSn9F68PjH9HqtltsSnqYC1XXoWe9Bju5+213R98cNGttag9q9yAOTzdbsqvIa7aNm5WffBZFpWYr2aWrklWAw=="
|
||||
},
|
||||
"object-inspect": {
|
||||
"version": "1.12.2",
|
||||
|
|
|
@ -64,6 +64,7 @@
|
|||
"@types/node-fetch": "^2.6.1",
|
||||
"@types/node-forge": "^1.0.2",
|
||||
"@types/node-ipc": "^9.2.0",
|
||||
"@types/object-hash": "^3.0.1",
|
||||
"@types/papaparse": "^5.3.2",
|
||||
"@types/proper-lockfile": "^4.1.2",
|
||||
"@types/retry": "^0.12.2",
|
||||
|
@ -176,6 +177,7 @@
|
|||
"node-fetch": "^2.6.7",
|
||||
"node-forge": "^1.3.1",
|
||||
"nord": "0.2.1",
|
||||
"object-hash": "^3.0.0",
|
||||
"open": "^8.4.0",
|
||||
"papaparse": "^5.3.2",
|
||||
"popper.js": "^1.16.1",
|
||||
|
|
Loading…
Reference in New Issue