A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
feat: use messagepack for syncing
thecodrrc234c87a76e6
diff --git a/packages/core/api/sync/index.js b/packages/core/api/sync/index.jsindex 9384ef0c7..0bb02a555 100644--- a/packages/core/api/sync/index.js+++ b/packages/core/api/sync/index.js@@ -15,6 +15,7 @@ import Conflicts from "./conflicts";import { SyncQueue } from "./syncqueue";import { AutoSync } from "./auto-sync";import { toChunks } from "../../utils/array";+import { MessagePackHubProtocol } from "@microsoft/signalr-protocol-msgpack";const ITEM_TYPE_MAP = {attachments: "attachment",@@ -58,8 +59,10 @@ export default class SyncManager {async start(full, force) {if (this.syncMutex.isLocked()) return false;return this.syncMutex.runExclusive(async () => {+ console.time("sync");await this.sync.autoSync.start();- return this.sync.start(full, force);+ await this.sync.start(full, force);+ console.timeEnd("sync");});}@@ -92,6 +95,7 @@ class Sync {.withUrl(`${Constants.API_HOST}/hubs/sync`, {accessTokenFactory: () => tokenManager.getAccessToken(),})+ .withHubProtocol(new MessagePackHubProtocol({ ignoreUndefined: true })).build();EV.subscribe(EVENTS.userLoggedOut, async () => {@@ -155,27 +159,28 @@ class Sync {async fetch(lastSynced) {const serverResponse = await new Promise((resolve, reject) => {- let counter = { count: 0 };+ let counter = { count: 0, queue: 0 };this.connection.stream("FetchItems", lastSynced).subscribe({- next: async (/** @type {SyncTransferItem} */ syncStatus) => {+ next: (/** @type {SyncTransferItem} */ syncStatus) => {const { total, item, synced, lastSynced } = syncStatus;try {if (synced || !item) return;- counter.count++;- await this.onSyncItem(syncStatus, counter);-- const progress = total - counter.count;- sendSyncProgressEvent(- this.db.eventManager,- `download`,- total,- progress- );+ ++counter.count;+ ++counter.queue;+ const progress = counter.count;+ this.onSyncItem(syncStatus).then(() => {+ sendSyncProgressEvent(+ this.db.eventManager,+ `download`,+ total,+ progress+ );+ });} catch (e) {reject(e);} finally {- if (--counter.count <= 0) resolve({ synced, lastSynced });+ if (--counter.queue <= 0) resolve({ synced, lastSynced });}},complete: () => {},@@ -225,8 +230,6 @@ class Sync {const { itemIds } = await this.queue.get();if (!itemIds) return false;- const total = itemIds.length;-const arrays = itemIds.reduce((arrays, id) => {const [arrayKey, itemId] = id.split(":");@@ -252,6 +255,8 @@ class Sync {arrays.items.push(JSON.stringify(data.vaultKey));}+ let total = arrays.ids.length;+arrays.ids = toChunks(arrays.ids, 30);arrays.types = toChunks(arrays.types, 30);arrays.items = toChunks(arrays.items, 30);diff --git a/packages/core/package-lock.json b/packages/core/package-lock.jsonindex 464f11033..8cd1716c4 100644--- a/packages/core/package-lock.json+++ b/packages/core/package-lock.json@@ -9,6 +9,7 @@"version": "6.16.4","dependencies": {"@microsoft/signalr": "^6.0.3",+ "@microsoft/signalr-protocol-msgpack": "^6.0.3","@stablelib/blake2s": "^1.0.1","async-mutex": "^0.3.2","base64-arraybuffer": "^1.0.1",@@ -1647,6 +1648,15 @@"ws": "^7.4.5"}},+ "node_modules/@microsoft/signalr-protocol-msgpack": {+ "version": "6.0.3",+ "resolved": "https://registry.npmjs.org/@microsoft/signalr-protocol-msgpack/-/signalr-protocol-msgpack-6.0.3.tgz",+ "integrity": "sha512-gL491qT3hw8Lu832gGBtvRklVG3Kp70gWaQQPYeSfifCGKAOcYDWJyiGMC7WN8pTtJ6kcaRRchda+3NCBVt3FQ==",+ "dependencies": {+ "@microsoft/signalr": ">=6.0.3",+ "@msgpack/msgpack": "^2.7.0"+ }+ },"node_modules/@microsoft/signalr/node_modules/eventsource": {"version": "1.1.0","resolved": "https://registry.npmjs.org/eventsource/-/eventsource-1.1.0.tgz",@@ -1696,6 +1706,14 @@"webidl-conversions": "^3.0.0"}},+ "node_modules/@msgpack/msgpack": {+ "version": "2.7.2",+ "resolved": "https://registry.npmjs.org/@msgpack/msgpack/-/msgpack-2.7.2.tgz",+ "integrity": "sha512-rYEi46+gIzufyYUAoHDnRzkWGxajpD9vVXFQ3g1vbjrBm6P7MBmm+s/fqPa46sxa+8FOUdEuRQKaugo5a4JWpw==",+ "engines": {+ "node": ">= 10"+ }+ },"node_modules/@nodelib/fs.scandir": {"version": "2.1.5","resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",@@ -11094,6 +11112,20 @@}}},+ "@microsoft/signalr-protocol-msgpack": {+ "version": "6.0.3",+ "resolved": "https://registry.npmjs.org/@microsoft/signalr-protocol-msgpack/-/signalr-protocol-msgpack-6.0.3.tgz",+ "integrity": "sha512-gL491qT3hw8Lu832gGBtvRklVG3Kp70gWaQQPYeSfifCGKAOcYDWJyiGMC7WN8pTtJ6kcaRRchda+3NCBVt3FQ==",+ "requires": {+ "@microsoft/signalr": ">=6.0.3",+ "@msgpack/msgpack": "^2.7.0"+ }+ },+ "@msgpack/msgpack": {+ "version": "2.7.2",+ "resolved": "https://registry.npmjs.org/@msgpack/msgpack/-/msgpack-2.7.2.tgz",+ "integrity": "sha512-rYEi46+gIzufyYUAoHDnRzkWGxajpD9vVXFQ3g1vbjrBm6P7MBmm+s/fqPa46sxa+8FOUdEuRQKaugo5a4JWpw=="+ },"@nodelib/fs.scandir": {"version": "2.1.5","resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",diff --git a/packages/core/package.json b/packages/core/package.jsonindex c966c5b82..aa2442d24 100644--- a/packages/core/package.json+++ b/packages/core/package.json@@ -29,6 +29,7 @@},"dependencies": {"@microsoft/signalr": "^6.0.3",+ "@microsoft/signalr-protocol-msgpack": "^6.0.3","@stablelib/blake2s": "^1.0.1","async-mutex": "^0.3.2","base64-arraybuffer": "^1.0.1",