mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-22 11:45:59 +01:00
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 { BehaviorSubject, concatMap, ReplaySubject, Subject, Subscription } from "rxjs";
|
||||||
|
|
||||||
import { Utils } from "@bitwarden/common/misc/utils";
|
import { Utils } from "@bitwarden/common/misc/utils";
|
||||||
@ -10,6 +11,7 @@ import { SyncedItemMetadata } from "./sync-item-metadata";
|
|||||||
export class SessionSyncer {
|
export class SessionSyncer {
|
||||||
subscription: Subscription;
|
subscription: Subscription;
|
||||||
id = Utils.newGuid();
|
id = Utils.newGuid();
|
||||||
|
lastHash: string;
|
||||||
|
|
||||||
// ignore initial values
|
// ignore initial values
|
||||||
private ignoreNUpdates = 0;
|
private ignoreNUpdates = 0;
|
||||||
@ -92,9 +94,13 @@ export class SessionSyncer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async updateSession(value: any) {
|
private async updateSession(value: any) {
|
||||||
|
const thisHash = objectHash(value);
|
||||||
|
if (thisHash !== this.lastHash) {
|
||||||
|
this.lastHash = thisHash;
|
||||||
await this.stateService.setInSessionMemory(this.metaData.sessionKey, value);
|
await this.stateService.setInSessionMemory(this.metaData.sessionKey, value);
|
||||||
await BrowserApi.sendMessage(this.updateMessageCommand, { id: this.id });
|
await BrowserApi.sendMessage(this.updateMessageCommand, { id: this.id });
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private get updateMessageCommand() {
|
private get updateMessageCommand() {
|
||||||
return `${this.metaData.sessionKey}_update`;
|
return `${this.metaData.sessionKey}_update`;
|
||||||
|
18
package-lock.json
generated
18
package-lock.json
generated
@ -54,6 +54,7 @@
|
|||||||
"node-fetch": "^2.6.7",
|
"node-fetch": "^2.6.7",
|
||||||
"node-forge": "^1.3.1",
|
"node-forge": "^1.3.1",
|
||||||
"nord": "0.2.1",
|
"nord": "0.2.1",
|
||||||
|
"object-hash": "^3.0.0",
|
||||||
"open": "^8.4.0",
|
"open": "^8.4.0",
|
||||||
"papaparse": "^5.3.2",
|
"papaparse": "^5.3.2",
|
||||||
"popper.js": "^1.16.1",
|
"popper.js": "^1.16.1",
|
||||||
@ -99,6 +100,7 @@
|
|||||||
"@types/node-fetch": "^2.6.1",
|
"@types/node-fetch": "^2.6.1",
|
||||||
"@types/node-forge": "^1.0.2",
|
"@types/node-forge": "^1.0.2",
|
||||||
"@types/node-ipc": "^9.2.0",
|
"@types/node-ipc": "^9.2.0",
|
||||||
|
"@types/object-hash": "^3.0.1",
|
||||||
"@types/papaparse": "^5.3.2",
|
"@types/papaparse": "^5.3.2",
|
||||||
"@types/proper-lockfile": "^4.1.2",
|
"@types/proper-lockfile": "^4.1.2",
|
||||||
"@types/retry": "^0.12.2",
|
"@types/retry": "^0.12.2",
|
||||||
@ -13024,6 +13026,12 @@
|
|||||||
"integrity": "sha512-WKG4gTr8przEZBiJ5r3s8ZIAoMXNbOgQ+j/d5O4X3x6kZJRLNvyUJuUK/KoG3+8BaOHPhp2m7WC6JKKeovDSzQ==",
|
"integrity": "sha512-WKG4gTr8przEZBiJ5r3s8ZIAoMXNbOgQ+j/d5O4X3x6kZJRLNvyUJuUK/KoG3+8BaOHPhp2m7WC6JKKeovDSzQ==",
|
||||||
"dev": true
|
"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": {
|
"node_modules/@types/papaparse": {
|
||||||
"version": "5.3.2",
|
"version": "5.3.2",
|
||||||
"resolved": "https://registry.npmjs.org/@types/papaparse/-/papaparse-5.3.2.tgz",
|
"resolved": "https://registry.npmjs.org/@types/papaparse/-/papaparse-5.3.2.tgz",
|
||||||
@ -32944,7 +32952,6 @@
|
|||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/object-hash/-/object-hash-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/object-hash/-/object-hash-3.0.0.tgz",
|
||||||
"integrity": "sha512-RSn9F68PjH9HqtltsSnqYC1XXoWe9Bju5+213R98cNGttag9q9yAOTzdbsqvIa7aNm5WffBZFpWYr2aWrklWAw==",
|
"integrity": "sha512-RSn9F68PjH9HqtltsSnqYC1XXoWe9Bju5+213R98cNGttag9q9yAOTzdbsqvIa7aNm5WffBZFpWYr2aWrklWAw==",
|
||||||
"dev": true,
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">= 6"
|
"node": ">= 6"
|
||||||
}
|
}
|
||||||
@ -52966,6 +52973,12 @@
|
|||||||
"integrity": "sha512-WKG4gTr8przEZBiJ5r3s8ZIAoMXNbOgQ+j/d5O4X3x6kZJRLNvyUJuUK/KoG3+8BaOHPhp2m7WC6JKKeovDSzQ==",
|
"integrity": "sha512-WKG4gTr8przEZBiJ5r3s8ZIAoMXNbOgQ+j/d5O4X3x6kZJRLNvyUJuUK/KoG3+8BaOHPhp2m7WC6JKKeovDSzQ==",
|
||||||
"dev": true
|
"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": {
|
"@types/papaparse": {
|
||||||
"version": "5.3.2",
|
"version": "5.3.2",
|
||||||
"resolved": "https://registry.npmjs.org/@types/papaparse/-/papaparse-5.3.2.tgz",
|
"resolved": "https://registry.npmjs.org/@types/papaparse/-/papaparse-5.3.2.tgz",
|
||||||
@ -68490,8 +68503,7 @@
|
|||||||
"object-hash": {
|
"object-hash": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/object-hash/-/object-hash-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/object-hash/-/object-hash-3.0.0.tgz",
|
||||||
"integrity": "sha512-RSn9F68PjH9HqtltsSnqYC1XXoWe9Bju5+213R98cNGttag9q9yAOTzdbsqvIa7aNm5WffBZFpWYr2aWrklWAw==",
|
"integrity": "sha512-RSn9F68PjH9HqtltsSnqYC1XXoWe9Bju5+213R98cNGttag9q9yAOTzdbsqvIa7aNm5WffBZFpWYr2aWrklWAw=="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"object-inspect": {
|
"object-inspect": {
|
||||||
"version": "1.12.2",
|
"version": "1.12.2",
|
||||||
|
@ -64,6 +64,7 @@
|
|||||||
"@types/node-fetch": "^2.6.1",
|
"@types/node-fetch": "^2.6.1",
|
||||||
"@types/node-forge": "^1.0.2",
|
"@types/node-forge": "^1.0.2",
|
||||||
"@types/node-ipc": "^9.2.0",
|
"@types/node-ipc": "^9.2.0",
|
||||||
|
"@types/object-hash": "^3.0.1",
|
||||||
"@types/papaparse": "^5.3.2",
|
"@types/papaparse": "^5.3.2",
|
||||||
"@types/proper-lockfile": "^4.1.2",
|
"@types/proper-lockfile": "^4.1.2",
|
||||||
"@types/retry": "^0.12.2",
|
"@types/retry": "^0.12.2",
|
||||||
@ -176,6 +177,7 @@
|
|||||||
"node-fetch": "^2.6.7",
|
"node-fetch": "^2.6.7",
|
||||||
"node-forge": "^1.3.1",
|
"node-forge": "^1.3.1",
|
||||||
"nord": "0.2.1",
|
"nord": "0.2.1",
|
||||||
|
"object-hash": "^3.0.0",
|
||||||
"open": "^8.4.0",
|
"open": "^8.4.0",
|
||||||
"papaparse": "^5.3.2",
|
"papaparse": "^5.3.2",
|
||||||
"popper.js": "^1.16.1",
|
"popper.js": "^1.16.1",
|
||||||
|
Loading…
Reference in New Issue
Block a user