mirror of
https://github.com/zadam/trilium.git
synced 2024-12-29 03:12:28 +08:00
load only expanded tree with the rest being lazy loaded, WIP
This commit is contained in:
parent
d57057ba28
commit
1687ed7e0b
10 changed files with 50 additions and 47 deletions
|
@ -388,10 +388,14 @@ imageId</ColNames>
|
|||
<column id="91" parent="13" name="title">
|
||||
<Position>2</Position>
|
||||
<DataType>TEXT|0s</DataType>
|
||||
<NotNull>1</NotNull>
|
||||
<DefaultExpression>"unnamed"</DefaultExpression>
|
||||
</column>
|
||||
<column id="92" parent="13" name="content">
|
||||
<Position>3</Position>
|
||||
<DataType>TEXT|0s</DataType>
|
||||
<NotNull>1</NotNull>
|
||||
<DefaultExpression>""</DefaultExpression>
|
||||
</column>
|
||||
<column id="93" parent="13" name="isProtected">
|
||||
<Position>4</Position>
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
INSERT INTO branches (branchId, noteId, parentNoteId, notePosition, prefix, isExpanded, isDeleted, dateModified) VALUES ('root', 'root', 'none', 0, null, 1, 0, '2018-01-01T00:00:00.000Z');
|
||||
INSERT INTO branches (branchId, noteId, parentNoteId, notePosition, prefix, isExpanded, isDeleted, dateModified) VALUES ('dLgtLUFn3GoN', '1Heh2acXfPNt', 'root', 21, null, 1, 0, '2017-12-23T00:46:39.304Z');
|
||||
INSERT INTO branches (branchId, noteId, parentNoteId, notePosition, prefix, isExpanded, isDeleted, dateModified) VALUES ('QLfS835GSfIh', '3RkyK9LI18dO', '1Heh2acXfPNt', 1, null, 1, 0, '2017-12-23T01:20:04.181Z');
|
||||
INSERT INTO branches (branchId, noteId, parentNoteId, notePosition, prefix, isExpanded, isDeleted, dateModified) VALUES ('QJAcYJ1gGUh9', 'L1Ox40M1aEyy', '3RkyK9LI18dO', 0, null, 0, 0, '2017-12-23T01:20:45.365Z');
|
||||
|
|
5
db/migrations/0089__add_root_branch.sql
Normal file
5
db/migrations/0089__add_root_branch.sql
Normal file
|
@ -0,0 +1,5 @@
|
|||
INSERT INTO branches (branchId, noteId, parentNoteId, notePosition, prefix, isExpanded, dateModified)
|
||||
VALUES ('root', 'root', 'none', 0, null, 1, '2018-01-01T00:00:00.000Z');
|
||||
|
||||
INSERT INTO sync (entityName, entityId, sourceId, syncDate)
|
||||
VALUES ('branches' ,'root', 'SYNC_FILL', '2018-01-01T00:00:00.000Z');
|
1
db/migrations/0090__branch_index.sql
Normal file
1
db/migrations/0090__branch_index.sql
Normal file
|
@ -0,0 +1 @@
|
|||
CREATE INDEX IDX_branches_parentNoteId ON branches (parentNoteId);
|
2
db/migrations/0091__drop_isDeleted_index.sql
Normal file
2
db/migrations/0091__drop_isDeleted_index.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
-- index confuses planner and is mostly useless anyway since we're mostly used in non-deleted notes (which are presumably majority)
|
||||
DROP INDEX IDX_notes_isDeleted;
|
|
@ -75,7 +75,7 @@ function goToLink(e) {
|
|||
}
|
||||
|
||||
function addLinkToEditor(linkTitle, linkHref) {
|
||||
const editor = noteDetailText.getEditor();
|
||||
const editor = noteDetailText.getEditor();Rum
|
||||
|
||||
editor.model.change( writer => {
|
||||
const insertPosition = editor.model.document.selection.getFirstPosition();
|
||||
|
|
|
@ -3,56 +3,46 @@
|
|||
const sql = require('../../services/sql');
|
||||
const optionService = require('../../services/options');
|
||||
const protectedSessionService = require('../../services/protected_session');
|
||||
const utils = require('../../services/utils');
|
||||
|
||||
async function getTree() {
|
||||
const branches = await sql.getRows(`
|
||||
SELECT
|
||||
branchId,
|
||||
noteId,
|
||||
parentNoteId,
|
||||
notePosition,
|
||||
prefix,
|
||||
isExpanded
|
||||
FROM
|
||||
branches
|
||||
WHERE
|
||||
isDeleted = 0
|
||||
ORDER BY
|
||||
notePosition`);
|
||||
WITH RECURSIVE
|
||||
tree(branchId, noteId, isExpanded) AS (
|
||||
SELECT branchId, noteId, isExpanded FROM branches WHERE branchId = 'root'
|
||||
UNION ALL
|
||||
SELECT branches.branchId, branches.noteId, branches.isExpanded FROM branches
|
||||
JOIN tree ON branches.parentNoteId = tree.noteId
|
||||
WHERE tree.isExpanded = 1 AND branches.isDeleted = 0
|
||||
)
|
||||
SELECT branches.* FROM tree JOIN branches USING(branchId);`);
|
||||
|
||||
const notes = [{
|
||||
noteId: 'root',
|
||||
title: 'root',
|
||||
isProtected: false,
|
||||
type: 'none',
|
||||
mime: 'none'
|
||||
}].concat(await sql.getRows(`
|
||||
SELECT
|
||||
notes.noteId,
|
||||
notes.title,
|
||||
notes.isProtected,
|
||||
notes.type,
|
||||
notes.mime,
|
||||
hideInAutocomplete.labelId AS 'hideInAutocomplete'
|
||||
FROM
|
||||
notes
|
||||
LEFT JOIN labels AS hideInAutocomplete ON hideInAutocomplete.noteId = notes.noteId
|
||||
AND hideInAutocomplete.name = 'hideInAutocomplete'
|
||||
AND hideInAutocomplete.isDeleted = 0
|
||||
WHERE
|
||||
notes.isDeleted = 0`));
|
||||
const noteIds = branches.map(b => b.noteId);
|
||||
const questionMarks = branches.map(() => "?").join(",");
|
||||
|
||||
const notes = await sql.getRows(`
|
||||
SELECT noteId, title, isProtected, type, mime
|
||||
FROM notes WHERE isDeleted = 0 AND noteId IN (${questionMarks})`, noteIds);
|
||||
|
||||
protectedSessionService.decryptNotes(notes);
|
||||
|
||||
notes.forEach(note => {
|
||||
note.hideInAutocomplete = !!note.hideInAutocomplete;
|
||||
note.isProtected = !!note.isProtected;
|
||||
});
|
||||
notes.forEach(note => note.isProtected = !!note.isProtected);
|
||||
|
||||
const relationships = await sql.getRows(`SELECT noteId, parentNoteId FROM branches WHERE isDeleted = 0
|
||||
AND parentNoteId IN (${questionMarks})`, noteIds);
|
||||
|
||||
const parentToChild = {};
|
||||
|
||||
for (const rel of relationships) {
|
||||
parentToChild[rel.parentNoteId] = parentToChild[rel.parentNoteId] || [];
|
||||
parentToChild[rel.parentNoteId].push(rel.noteId);
|
||||
}
|
||||
|
||||
return {
|
||||
startNotePath: await optionService.getOption('startNotePath'),
|
||||
branches: branches,
|
||||
notes: notes
|
||||
notes: notes,
|
||||
parentToChild
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
const build = require('./build');
|
||||
const packageJson = require('../../package');
|
||||
|
||||
const APP_DB_VERSION = 88;
|
||||
const APP_DB_VERSION = 91;
|
||||
|
||||
module.exports = {
|
||||
appVersion: packageJson.version,
|
||||
|
|
|
@ -116,7 +116,7 @@ async function runAllChecks() {
|
|||
WHERE
|
||||
notes.isDeleted = 1
|
||||
AND branches.isDeleted = 0`,
|
||||
"Note tree is not deleted even though main note is deleted for following branch IDs", errorList);
|
||||
"Branch is not deleted even though main note is deleted for following branch IDs", errorList);
|
||||
|
||||
await runCheck(`
|
||||
SELECT
|
||||
|
@ -125,12 +125,12 @@ async function runAllChecks() {
|
|||
branches AS child
|
||||
WHERE
|
||||
child.isDeleted = 0
|
||||
AND child.parentNoteId != 'root'
|
||||
AND child.parentNoteId != 'none'
|
||||
AND (SELECT COUNT(*) FROM branches AS parent WHERE parent.noteId = child.parentNoteId
|
||||
AND parent.isDeleted = 0) = 0`,
|
||||
"All parent branches are deleted but child note tree is not for these child note tree IDs", errorList);
|
||||
"All parent branches are deleted but child branch is not for these child branch IDs", errorList);
|
||||
|
||||
// we do extra JOIN to eliminate orphan notes without note tree (which are reported separately)
|
||||
// we do extra JOIN to eliminate orphan notes without branches (which are reported separately)
|
||||
await runCheck(`
|
||||
SELECT
|
||||
DISTINCT noteId
|
||||
|
@ -150,7 +150,7 @@ async function runAllChecks() {
|
|||
LEFT JOIN branches AS parent ON parent.noteId = child.parentNoteId
|
||||
WHERE
|
||||
parent.noteId IS NULL
|
||||
AND child.parentNoteId != 'root'`,
|
||||
AND child.parentNoteId != 'none'`,
|
||||
"Not existing parent in the following parent > child relations", errorList);
|
||||
|
||||
await runCheck(`
|
||||
|
|
|
@ -58,7 +58,7 @@ async function start() {
|
|||
}
|
||||
|
||||
// we'll create clones for 20% of notes
|
||||
for (let i = 0; i < (noteCount / 5); i++) {
|
||||
for (let i = 0; i < (noteCount / 50); i++) {
|
||||
const noteIdToClone = getRandomParentNoteId();
|
||||
const parentNoteId = getRandomParentNoteId();
|
||||
const prefix = Math.random() > 0.8 ? "prefix" : null;
|
||||
|
|
Loading…
Reference in a new issue