mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
load only expanded tree with the rest being lazy loaded, WIP
This commit is contained in:
parent
d57057ba28
commit
1687ed7e0b
@ -388,10 +388,14 @@ imageId</ColNames>
|
|||||||
<column id="91" parent="13" name="title">
|
<column id="91" parent="13" name="title">
|
||||||
<Position>2</Position>
|
<Position>2</Position>
|
||||||
<DataType>TEXT|0s</DataType>
|
<DataType>TEXT|0s</DataType>
|
||||||
|
<NotNull>1</NotNull>
|
||||||
|
<DefaultExpression>"unnamed"</DefaultExpression>
|
||||||
</column>
|
</column>
|
||||||
<column id="92" parent="13" name="content">
|
<column id="92" parent="13" name="content">
|
||||||
<Position>3</Position>
|
<Position>3</Position>
|
||||||
<DataType>TEXT|0s</DataType>
|
<DataType>TEXT|0s</DataType>
|
||||||
|
<NotNull>1</NotNull>
|
||||||
|
<DefaultExpression>""</DefaultExpression>
|
||||||
</column>
|
</column>
|
||||||
<column id="93" parent="13" name="isProtected">
|
<column id="93" parent="13" name="isProtected">
|
||||||
<Position>4</Position>
|
<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 ('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 ('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');
|
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) {
|
function addLinkToEditor(linkTitle, linkHref) {
|
||||||
const editor = noteDetailText.getEditor();
|
const editor = noteDetailText.getEditor();Rum
|
||||||
|
|
||||||
editor.model.change( writer => {
|
editor.model.change( writer => {
|
||||||
const insertPosition = editor.model.document.selection.getFirstPosition();
|
const insertPosition = editor.model.document.selection.getFirstPosition();
|
||||||
|
@ -3,56 +3,46 @@
|
|||||||
const sql = require('../../services/sql');
|
const sql = require('../../services/sql');
|
||||||
const optionService = require('../../services/options');
|
const optionService = require('../../services/options');
|
||||||
const protectedSessionService = require('../../services/protected_session');
|
const protectedSessionService = require('../../services/protected_session');
|
||||||
|
const utils = require('../../services/utils');
|
||||||
|
|
||||||
async function getTree() {
|
async function getTree() {
|
||||||
const branches = await sql.getRows(`
|
const branches = await sql.getRows(`
|
||||||
SELECT
|
WITH RECURSIVE
|
||||||
branchId,
|
tree(branchId, noteId, isExpanded) AS (
|
||||||
noteId,
|
SELECT branchId, noteId, isExpanded FROM branches WHERE branchId = 'root'
|
||||||
parentNoteId,
|
UNION ALL
|
||||||
notePosition,
|
SELECT branches.branchId, branches.noteId, branches.isExpanded FROM branches
|
||||||
prefix,
|
JOIN tree ON branches.parentNoteId = tree.noteId
|
||||||
isExpanded
|
WHERE tree.isExpanded = 1 AND branches.isDeleted = 0
|
||||||
FROM
|
)
|
||||||
branches
|
SELECT branches.* FROM tree JOIN branches USING(branchId);`);
|
||||||
WHERE
|
|
||||||
isDeleted = 0
|
|
||||||
ORDER BY
|
|
||||||
notePosition`);
|
|
||||||
|
|
||||||
const notes = [{
|
const noteIds = branches.map(b => b.noteId);
|
||||||
noteId: 'root',
|
const questionMarks = branches.map(() => "?").join(",");
|
||||||
title: 'root',
|
|
||||||
isProtected: false,
|
const notes = await sql.getRows(`
|
||||||
type: 'none',
|
SELECT noteId, title, isProtected, type, mime
|
||||||
mime: 'none'
|
FROM notes WHERE isDeleted = 0 AND noteId IN (${questionMarks})`, noteIds);
|
||||||
}].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`));
|
|
||||||
|
|
||||||
protectedSessionService.decryptNotes(notes);
|
protectedSessionService.decryptNotes(notes);
|
||||||
|
|
||||||
notes.forEach(note => {
|
notes.forEach(note => note.isProtected = !!note.isProtected);
|
||||||
note.hideInAutocomplete = !!note.hideInAutocomplete;
|
|
||||||
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 {
|
return {
|
||||||
startNotePath: await optionService.getOption('startNotePath'),
|
startNotePath: await optionService.getOption('startNotePath'),
|
||||||
branches: branches,
|
branches: branches,
|
||||||
notes: notes
|
notes: notes,
|
||||||
|
parentToChild
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
const build = require('./build');
|
const build = require('./build');
|
||||||
const packageJson = require('../../package');
|
const packageJson = require('../../package');
|
||||||
|
|
||||||
const APP_DB_VERSION = 88;
|
const APP_DB_VERSION = 91;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
appVersion: packageJson.version,
|
appVersion: packageJson.version,
|
||||||
|
@ -116,7 +116,7 @@ async function runAllChecks() {
|
|||||||
WHERE
|
WHERE
|
||||||
notes.isDeleted = 1
|
notes.isDeleted = 1
|
||||||
AND branches.isDeleted = 0`,
|
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(`
|
await runCheck(`
|
||||||
SELECT
|
SELECT
|
||||||
@ -125,12 +125,12 @@ async function runAllChecks() {
|
|||||||
branches AS child
|
branches AS child
|
||||||
WHERE
|
WHERE
|
||||||
child.isDeleted = 0
|
child.isDeleted = 0
|
||||||
AND child.parentNoteId != 'root'
|
AND child.parentNoteId != 'none'
|
||||||
AND (SELECT COUNT(*) FROM branches AS parent WHERE parent.noteId = child.parentNoteId
|
AND (SELECT COUNT(*) FROM branches AS parent WHERE parent.noteId = child.parentNoteId
|
||||||
AND parent.isDeleted = 0) = 0`,
|
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(`
|
await runCheck(`
|
||||||
SELECT
|
SELECT
|
||||||
DISTINCT noteId
|
DISTINCT noteId
|
||||||
@ -150,7 +150,7 @@ async function runAllChecks() {
|
|||||||
LEFT JOIN branches AS parent ON parent.noteId = child.parentNoteId
|
LEFT JOIN branches AS parent ON parent.noteId = child.parentNoteId
|
||||||
WHERE
|
WHERE
|
||||||
parent.noteId IS NULL
|
parent.noteId IS NULL
|
||||||
AND child.parentNoteId != 'root'`,
|
AND child.parentNoteId != 'none'`,
|
||||||
"Not existing parent in the following parent > child relations", errorList);
|
"Not existing parent in the following parent > child relations", errorList);
|
||||||
|
|
||||||
await runCheck(`
|
await runCheck(`
|
||||||
|
@ -58,7 +58,7 @@ async function start() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// we'll create clones for 20% of notes
|
// 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 noteIdToClone = getRandomParentNoteId();
|
||||||
const parentNoteId = getRandomParentNoteId();
|
const parentNoteId = getRandomParentNoteId();
|
||||||
const prefix = Math.random() > 0.8 ? "prefix" : null;
|
const prefix = Math.random() > 0.8 ? "prefix" : null;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user