From 85d13b1d6269900b2d3d06ae2dadf50b30fee1ab Mon Sep 17 00:00:00 2001 From: zadam Date: Mon, 14 Sep 2020 22:48:20 +0200 Subject: [PATCH] resort relationships in tree cache after note reordering --- package-lock.json | 77 +++++++++++++++------------ package.json | 2 +- src/public/app/entities/note_short.js | 4 ++ src/public/app/services/ws.js | 13 +++++ src/public/app/widgets/note_tree.js | 3 ++ 5 files changed, 65 insertions(+), 34 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2279075a9..be9127bb6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "trilium", - "version": "0.44.1-beta", + "version": "0.44.2-beta", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -1595,9 +1595,9 @@ } }, "better-sqlite3": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-7.1.0.tgz", - "integrity": "sha512-FV/snQ8F/kyqhdxsevzbojVtMowDWOfe1A5N3lYu1KJwoho2t7JgITmdlSc7DkOh3Zq65I+ZyeNWXQrkLEDFTg==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-7.1.1.tgz", + "integrity": "sha512-AkvGGyhAVZhRBOul2WT+5CB2EuveM3ZkebEKe1wxMqDZUy1XB/1RBgM66t0ybHC4DIni8+pr7NaLqEX87NUTwg==", "requires": { "bindings": "^1.5.0", "prebuild-install": "^5.3.3", @@ -1628,6 +1628,33 @@ "file-uri-to-path": "1.0.0" } }, + "bl": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/bl/-/bl-4.0.3.tgz", + "integrity": "sha512-fs4G6/Hu4/EE+F75J8DuN/0IpQqNjAdC7aEQv7Qt8MHGUH7Ckv2MwTEEeN9QehD0pfIDkMI1bkHYkKy7xHyKIg==", + "requires": { + "buffer": "^5.5.0", + "inherits": "^2.0.4", + "readable-stream": "^3.4.0" + }, + "dependencies": { + "inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "readable-stream": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + } + } + }, "bluebird": { "version": "3.7.0", "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.0.tgz", @@ -2138,9 +2165,9 @@ } }, "chownr": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.3.tgz", - "integrity": "sha512-i70fVHhmV3DtTl6nqvZOnIjbY0Pe4kAUjwHj8z0zAdgBtYrJyYwLKCCuRBQ5ppkyL0AkN7HKRnETdmdp1zqNXw==" + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.4.tgz", + "integrity": "sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg==" }, "chrome-trace-event": { "version": "1.0.2", @@ -6888,9 +6915,9 @@ } }, "prebuild-install": { - "version": "5.3.4", - "resolved": "https://registry.npmjs.org/prebuild-install/-/prebuild-install-5.3.4.tgz", - "integrity": "sha512-AkKN+pf4fSEihjapLEEj8n85YIw/tN6BQqkhzbDc0RvEZGdkpJBGMUYx66AAMcPG2KzmPQS7Cm16an4HVBRRMA==", + "version": "5.3.5", + "resolved": "https://registry.npmjs.org/prebuild-install/-/prebuild-install-5.3.5.tgz", + "integrity": "sha512-YmMO7dph9CYKi5IR/BzjOJlRzpxGGVo1EsLSUZ0mt/Mq0HWZIHOKHHcHdT69yG54C9m6i45GpItwRHpk0Py7Uw==", "requires": { "detect-libc": "^1.0.3", "expand-template": "^2.0.3", @@ -6913,14 +6940,6 @@ "version": "1.2.5", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" - }, - "tunnel-agent": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", - "integrity": "sha1-J6XeoGs2sEoKmWZ3SykIaPD8QP0=", - "requires": { - "safe-buffer": "^5.0.1" - } } } }, @@ -7779,9 +7798,9 @@ "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=" }, "simple-concat": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/simple-concat/-/simple-concat-1.0.0.tgz", - "integrity": "sha1-c0TLuLbib7J9ZrL8hvn21Zl1IcY=" + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/simple-concat/-/simple-concat-1.0.1.tgz", + "integrity": "sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q==" }, "simple-get": { "version": "3.1.0", @@ -8342,25 +8361,17 @@ } }, "tar-stream": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.1.2.tgz", - "integrity": "sha512-UaF6FoJ32WqALZGOIAApXx+OdxhekNMChu6axLJR85zMMjXKWFGjbIRe+J6P4UnRGg9rAwWvbTT0oI7hD/Un7Q==", + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.1.4.tgz", + "integrity": "sha512-o3pS2zlG4gxr67GmFYBLlq+dM8gyRGUOvsrHclSkvtVtQbjV0s/+ZE8OpICbaj8clrX3tjeHngYGP7rweaBnuw==", "requires": { - "bl": "^4.0.1", + "bl": "^4.0.3", "end-of-stream": "^1.4.1", "fs-constants": "^1.0.0", "inherits": "^2.0.3", "readable-stream": "^3.1.1" }, "dependencies": { - "bl": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/bl/-/bl-4.0.1.tgz", - "integrity": "sha512-FL/TdvchukRCuWVxT0YMO/7+L5TNeNrVFvRU2IY63aUyv9mpt8splf2NEr6qXtPo5fya5a66YohQKvGNmLrWNA==", - "requires": { - "readable-stream": "^3.4.0" - } - }, "readable-stream": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", diff --git a/package.json b/package.json index aa57e9b93..378dbc390 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "dependencies": { "async-mutex": "0.2.4", "axios": "0.20.0", - "better-sqlite3": "7.1.0", + "better-sqlite3": "7.1.1", "body-parser": "1.19.0", "cls-hooked": "4.2.2", "commonmark": "0.29.2", diff --git a/src/public/app/entities/note_short.js b/src/public/app/entities/note_short.js index d0a1744fb..384e4f35d 100644 --- a/src/public/app/entities/note_short.js +++ b/src/public/app/entities/note_short.js @@ -72,6 +72,10 @@ class NoteShort { this.childToBranch[childNoteId] = branchId; + this.sortChildren(); + } + + sortChildren() { const branchIdPos = {}; for (const branchId of Object.values(this.childToBranch)) { diff --git a/src/public/app/services/ws.js b/src/public/app/services/ws.js index 69d868116..021ea0ca5 100644 --- a/src/public/app/services/ws.js +++ b/src/public/app/services/ws.js @@ -7,6 +7,7 @@ import Attribute from "../entities/attribute.js"; import options from "./options.js"; import treeCache from "./tree_cache.js"; import noteAttributeCache from "./note_attribute_cache.js"; +import tree from "./tree.js"; const $outstandingSyncsCount = $("#outstanding-syncs-count"); @@ -306,11 +307,23 @@ async function processSyncRows(syncRows) { } for (const sync of syncRows.filter(sync => sync.entityName === 'note_reordering')) { + const parentNoteIdsToSort = new Set(); + for (const branchId in sync.positions) { const branch = treeCache.branches[branchId]; if (branch) { branch.notePosition = sync.positions[branchId]; + + parentNoteIdsToSort.add(branch.parentNoteId); + } + } + + for (const parentNoteId of parentNoteIdsToSort) { + const parentNote = treeCache.notes[parentNoteId]; + + if (parentNote) { + parentNote.sortChildren(); } } diff --git a/src/public/app/widgets/note_tree.js b/src/public/app/widgets/note_tree.js index d189e252b..013deb525 100644 --- a/src/public/app/widgets/note_tree.js +++ b/src/public/app/widgets/note_tree.js @@ -1066,6 +1066,9 @@ export default class NoteTreeWidget extends TabAwareWidget { parentNode.addChildren([this.prepareNode(branch, true)]); this.sortChildren(parentNode); + + // this might be a first child which would force an icon change + noteIdsToUpdate.add(branch.parentNoteId); } } }