resort relationships in tree cache after note reordering

This commit is contained in:
zadam 2020-09-14 22:48:20 +02:00
parent f5f48ef6c4
commit 85d13b1d62
5 changed files with 65 additions and 34 deletions

77
package-lock.json generated
View file

@ -1,6 +1,6 @@
{ {
"name": "trilium", "name": "trilium",
"version": "0.44.1-beta", "version": "0.44.2-beta",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@ -1595,9 +1595,9 @@
} }
}, },
"better-sqlite3": { "better-sqlite3": {
"version": "7.1.0", "version": "7.1.1",
"resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-7.1.0.tgz", "resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-7.1.1.tgz",
"integrity": "sha512-FV/snQ8F/kyqhdxsevzbojVtMowDWOfe1A5N3lYu1KJwoho2t7JgITmdlSc7DkOh3Zq65I+ZyeNWXQrkLEDFTg==", "integrity": "sha512-AkvGGyhAVZhRBOul2WT+5CB2EuveM3ZkebEKe1wxMqDZUy1XB/1RBgM66t0ybHC4DIni8+pr7NaLqEX87NUTwg==",
"requires": { "requires": {
"bindings": "^1.5.0", "bindings": "^1.5.0",
"prebuild-install": "^5.3.3", "prebuild-install": "^5.3.3",
@ -1628,6 +1628,33 @@
"file-uri-to-path": "1.0.0" "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": { "bluebird": {
"version": "3.7.0", "version": "3.7.0",
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.0.tgz", "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.0.tgz",
@ -2138,9 +2165,9 @@
} }
}, },
"chownr": { "chownr": {
"version": "1.1.3", "version": "1.1.4",
"resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.3.tgz", "resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.4.tgz",
"integrity": "sha512-i70fVHhmV3DtTl6nqvZOnIjbY0Pe4kAUjwHj8z0zAdgBtYrJyYwLKCCuRBQ5ppkyL0AkN7HKRnETdmdp1zqNXw==" "integrity": "sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg=="
}, },
"chrome-trace-event": { "chrome-trace-event": {
"version": "1.0.2", "version": "1.0.2",
@ -6888,9 +6915,9 @@
} }
}, },
"prebuild-install": { "prebuild-install": {
"version": "5.3.4", "version": "5.3.5",
"resolved": "https://registry.npmjs.org/prebuild-install/-/prebuild-install-5.3.4.tgz", "resolved": "https://registry.npmjs.org/prebuild-install/-/prebuild-install-5.3.5.tgz",
"integrity": "sha512-AkKN+pf4fSEihjapLEEj8n85YIw/tN6BQqkhzbDc0RvEZGdkpJBGMUYx66AAMcPG2KzmPQS7Cm16an4HVBRRMA==", "integrity": "sha512-YmMO7dph9CYKi5IR/BzjOJlRzpxGGVo1EsLSUZ0mt/Mq0HWZIHOKHHcHdT69yG54C9m6i45GpItwRHpk0Py7Uw==",
"requires": { "requires": {
"detect-libc": "^1.0.3", "detect-libc": "^1.0.3",
"expand-template": "^2.0.3", "expand-template": "^2.0.3",
@ -6913,14 +6940,6 @@
"version": "1.2.5", "version": "1.2.5",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" "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=" "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0="
}, },
"simple-concat": { "simple-concat": {
"version": "1.0.0", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/simple-concat/-/simple-concat-1.0.0.tgz", "resolved": "https://registry.npmjs.org/simple-concat/-/simple-concat-1.0.1.tgz",
"integrity": "sha1-c0TLuLbib7J9ZrL8hvn21Zl1IcY=" "integrity": "sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q=="
}, },
"simple-get": { "simple-get": {
"version": "3.1.0", "version": "3.1.0",
@ -8342,25 +8361,17 @@
} }
}, },
"tar-stream": { "tar-stream": {
"version": "2.1.2", "version": "2.1.4",
"resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.1.2.tgz", "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.1.4.tgz",
"integrity": "sha512-UaF6FoJ32WqALZGOIAApXx+OdxhekNMChu6axLJR85zMMjXKWFGjbIRe+J6P4UnRGg9rAwWvbTT0oI7hD/Un7Q==", "integrity": "sha512-o3pS2zlG4gxr67GmFYBLlq+dM8gyRGUOvsrHclSkvtVtQbjV0s/+ZE8OpICbaj8clrX3tjeHngYGP7rweaBnuw==",
"requires": { "requires": {
"bl": "^4.0.1", "bl": "^4.0.3",
"end-of-stream": "^1.4.1", "end-of-stream": "^1.4.1",
"fs-constants": "^1.0.0", "fs-constants": "^1.0.0",
"inherits": "^2.0.3", "inherits": "^2.0.3",
"readable-stream": "^3.1.1" "readable-stream": "^3.1.1"
}, },
"dependencies": { "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": { "readable-stream": {
"version": "3.6.0", "version": "3.6.0",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz",

View file

@ -26,7 +26,7 @@
"dependencies": { "dependencies": {
"async-mutex": "0.2.4", "async-mutex": "0.2.4",
"axios": "0.20.0", "axios": "0.20.0",
"better-sqlite3": "7.1.0", "better-sqlite3": "7.1.1",
"body-parser": "1.19.0", "body-parser": "1.19.0",
"cls-hooked": "4.2.2", "cls-hooked": "4.2.2",
"commonmark": "0.29.2", "commonmark": "0.29.2",

View file

@ -72,6 +72,10 @@ class NoteShort {
this.childToBranch[childNoteId] = branchId; this.childToBranch[childNoteId] = branchId;
this.sortChildren();
}
sortChildren() {
const branchIdPos = {}; const branchIdPos = {};
for (const branchId of Object.values(this.childToBranch)) { for (const branchId of Object.values(this.childToBranch)) {

View file

@ -7,6 +7,7 @@ import Attribute from "../entities/attribute.js";
import options from "./options.js"; import options from "./options.js";
import treeCache from "./tree_cache.js"; import treeCache from "./tree_cache.js";
import noteAttributeCache from "./note_attribute_cache.js"; import noteAttributeCache from "./note_attribute_cache.js";
import tree from "./tree.js";
const $outstandingSyncsCount = $("#outstanding-syncs-count"); const $outstandingSyncsCount = $("#outstanding-syncs-count");
@ -306,11 +307,23 @@ async function processSyncRows(syncRows) {
} }
for (const sync of syncRows.filter(sync => sync.entityName === 'note_reordering')) { for (const sync of syncRows.filter(sync => sync.entityName === 'note_reordering')) {
const parentNoteIdsToSort = new Set();
for (const branchId in sync.positions) { for (const branchId in sync.positions) {
const branch = treeCache.branches[branchId]; const branch = treeCache.branches[branchId];
if (branch) { if (branch) {
branch.notePosition = sync.positions[branchId]; branch.notePosition = sync.positions[branchId];
parentNoteIdsToSort.add(branch.parentNoteId);
}
}
for (const parentNoteId of parentNoteIdsToSort) {
const parentNote = treeCache.notes[parentNoteId];
if (parentNote) {
parentNote.sortChildren();
} }
} }

View file

@ -1066,6 +1066,9 @@ export default class NoteTreeWidget extends TabAwareWidget {
parentNode.addChildren([this.prepareNode(branch, true)]); parentNode.addChildren([this.prepareNode(branch, true)]);
this.sortChildren(parentNode); this.sortChildren(parentNode);
// this might be a first child which would force an icon change
noteIdsToUpdate.add(branch.parentNoteId);
} }
} }
} }