mirror of
https://github.com/zadam/trilium.git
synced 2025-10-30 01:36:24 +01:00
fix DB setup
This commit is contained in:
@@ -3,23 +3,31 @@
|
||||
const sql = require('../sql.js');
|
||||
const eventService = require('../events.js');
|
||||
const noteCache = require('./note_cache');
|
||||
const sqlInit = require('../sql_init');
|
||||
const Note = require('./entities/note');
|
||||
const Branch = require('./entities/branch');
|
||||
const Attribute = require('./entities/attribute');
|
||||
|
||||
sqlInit.dbReady.then(() => {
|
||||
load();
|
||||
});
|
||||
|
||||
function load() {
|
||||
noteCache.reset();
|
||||
|
||||
sql.getRows(`SELECT noteId, title, type, mime, isProtected, dateCreated, dateModified, utcDateCreated, utcDateModified, contentLength FROM notes WHERE isDeleted = 0`, [])
|
||||
.map(row => new Note(noteCache, row));
|
||||
for (const row of sql.iterateRows(`SELECT noteId, title, type, mime, isProtected, dateCreated, dateModified, utcDateCreated, utcDateModified, contentLength FROM notes WHERE isDeleted = 0`, [])) {
|
||||
new Note(noteCache, row);
|
||||
}
|
||||
|
||||
sql.getRows(`SELECT branchId, noteId, parentNoteId, prefix FROM branches WHERE isDeleted = 0`, [])
|
||||
.map(row => new Branch(noteCache, row));
|
||||
for (const row of sql.iterateRows(`SELECT branchId, noteId, parentNoteId, prefix FROM branches WHERE isDeleted = 0`, [])) {
|
||||
new Branch(noteCache, row);
|
||||
}
|
||||
|
||||
sql.getRows(`SELECT attributeId, noteId, type, name, value, isInheritable FROM attributes WHERE isDeleted = 0`, []).map(row => new Attribute(noteCache, row));
|
||||
for (const row of sql.iterateRows(`SELECT attributeId, noteId, type, name, value, isInheritable FROM attributes WHERE isDeleted = 0`, [])) {
|
||||
new Attribute(noteCache, row);
|
||||
}
|
||||
|
||||
noteCache.loaded = true;
|
||||
noteCache.loadedResolve();
|
||||
}
|
||||
|
||||
eventService.subscribe([eventService.ENTITY_CHANGED, eventService.ENTITY_DELETED, eventService.ENTITY_SYNCED], ({entityName, entity}) => {
|
||||
@@ -144,7 +152,5 @@ eventService.subscribe([eventService.ENTITY_CHANGED, eventService.ENTITY_DELETED
|
||||
});
|
||||
|
||||
eventService.subscribe(eventService.ENTER_PROTECTED_SESSION, () => {
|
||||
noteCache.loadedPromise.then(() => noteCache.decryptProtectedNotes());
|
||||
noteCache.decryptProtectedNotes();
|
||||
});
|
||||
|
||||
load();
|
||||
|
||||
Reference in New Issue
Block a user