Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fixed initial demo import
zadamc4cc48dfc944
diff --git a/src/routes/api/setup.js b/src/routes/api/setup.jsindex 7c3dfed106..98cdd63276 100644--- a/src/routes/api/setup.js+++ b/src/routes/api/setup.js@@ -13,10 +13,10 @@ function getStatus() {};}-function setupNewDocument(req) {+async function setupNewDocument(req) {const { username, password, theme } = req.body;- sqlInit.createInitialDatabase(username, password, theme);+ await sqlInit.createInitialDatabase(username, password, theme);}function setupSyncFromServer(req) {diff --git a/src/services/options.js b/src/services/options.jsindex efbd3ef447..92ff7b3dcf 100644--- a/src/services/options.js+++ b/src/services/options.js@@ -1,5 +1,3 @@-const utils = require('./utils');-function getOption(name) {const option = require('./repository').getOption(name);diff --git a/src/services/sql_init.js b/src/services/sql_init.jsindex a3aa5b2c4a..7a734a5e00 100644--- a/src/services/sql_init.js+++ b/src/services/sql_init.js@@ -55,7 +55,7 @@ function initDbConnection() {dbReady.resolve();}-function createInitialDatabase(username, password, theme) {+async function createInitialDatabase(username, password, theme) {log.info("Creating initial database ...");if (isDbInitialized()) {@@ -65,13 +65,15 @@ function createInitialDatabase(username, password, theme) {const schema = fs.readFileSync(resourceDir.DB_INIT_DIR + '/schema.sql', 'UTF-8');const demoFile = fs.readFileSync(resourceDir.DB_INIT_DIR + '/demo.zip');+ let rootNote;+sql.transactional(() => {sql.executeScript(schema);const Note = require("../entities/note");const Branch = require("../entities/branch");- const rootNote = new Note({+ rootNote = new Note({noteId: 'root',title: 'root',type: 'text',@@ -87,12 +89,16 @@ function createInitialDatabase(username, password, theme) {isExpanded: true,notePosition: 10}).save();+ });++ const dummyTaskContext = new TaskContext("initial-demo-import", 'import', false);- const dummyTaskContext = new TaskContext("1", 'import', false);+ const zipImportService = require("./import/zip");+ await zipImportService.importZip(dummyTaskContext, demoFile, rootNote);- const zipImportService = require("./import/zip");- zipImportService.importZip(dummyTaskContext, demoFile, rootNote);+ require('./sync_table').fillAllSyncRows();+ sql.transactional(() => {const startNoteId = sql.getValue("SELECT noteId FROM branches WHERE parentNoteId = 'root' AND isDeleted = 0 ORDER BY notePosition");const optionsInitService = require('./options_init');@@ -100,8 +106,6 @@ function createInitialDatabase(username, password, theme) {optionsInitService.initDocumentOptions();optionsInitService.initSyncedOptions(username, password);optionsInitService.initNotSyncedOptions(true, startNoteId, { theme });-- require('./sync_table').fillAllSyncRows();});log.info("Schema and initial content generated.");diff --git a/src/services/sync_table.js b/src/services/sync_table.jsindex 3e51d82cde..343e5d9d01 100644--- a/src/services/sync_table.js+++ b/src/services/sync_table.js@@ -99,17 +99,19 @@ function fillSyncRows(entityName, entityPrimaryKey, condition = '') {}function fillAllSyncRows() {- sql.execute("DELETE FROM sync");-- fillSyncRows("notes", "noteId");- fillSyncRows("note_contents", "noteId");- fillSyncRows("branches", "branchId");- fillSyncRows("note_revisions", "noteRevisionId");- fillSyncRows("note_revision_contents", "noteRevisionId");- fillSyncRows("recent_notes", "noteId");- fillSyncRows("attributes", "attributeId");- fillSyncRows("api_tokens", "apiTokenId");- fillSyncRows("options", "name", 'isSynced = 1');+ sql.transactional(() => {+ sql.execute("DELETE FROM sync");++ fillSyncRows("notes", "noteId");+ fillSyncRows("note_contents", "noteId");+ fillSyncRows("branches", "branchId");+ fillSyncRows("note_revisions", "noteRevisionId");+ fillSyncRows("note_revision_contents", "noteRevisionId");+ fillSyncRows("recent_notes", "noteId");+ fillSyncRows("attributes", "attributeId");+ fillSyncRows("api_tokens", "apiTokenId");+ fillSyncRows("options", "name", 'isSynced = 1');+ });}module.exports = {diff --git a/src/services/task_context.js b/src/services/task_context.jsindex 9c4c354b05..0edd3c0bba 100644--- a/src/services/task_context.js+++ b/src/services/task_context.js@@ -34,7 +34,7 @@ class TaskContext {increaseProgressCount() {this.progressCount++;- if (Date.now() - this.lastSentCountTs >= 300) {+ if (Date.now() - this.lastSentCountTs >= 300 && this.taskId !== 'initial-demo-import') {this.lastSentCountTs = Date.now();ws.sendMessageToAllClients({@@ -68,4 +68,4 @@ class TaskContext {}}-module.exports = TaskContext;\ No newline at end of file+module.exports = TaskContext;