mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
reorder database initialization so that all critical sections are in the same transaction, #1985
This commit is contained in:
parent
a76e3f6e2d
commit
56378cd0f5
@ -27,10 +27,10 @@ function initSyncedOptions(username, password) {
|
|||||||
passwordEncryptionService.setDataKey(password, utils.randomSecureToken(16), true);
|
passwordEncryptionService.setDataKey(password, utils.randomSecureToken(16), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function initNotSyncedOptions(initialized, startNotePath = 'root', opts = {}) {
|
function initNotSyncedOptions(initialized, opts = {}) {
|
||||||
optionService.createOption('openTabs', JSON.stringify([
|
optionService.createOption('openTabs', JSON.stringify([
|
||||||
{
|
{
|
||||||
notePath: startNotePath,
|
notePath: 'root',
|
||||||
active: true
|
active: true
|
||||||
}
|
}
|
||||||
]), false);
|
]), false);
|
||||||
@ -98,7 +98,7 @@ function initStartupOptions() {
|
|||||||
if (!(name in optionsMap)) {
|
if (!(name in optionsMap)) {
|
||||||
optionService.createOption(name, value, isSynced);
|
optionService.createOption(name, value, isSynced);
|
||||||
|
|
||||||
log.info(`Created missing option "${name}" with default value "${value}"`);
|
log.info(`Created option "${name}" with default value "${value}"`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,6 +82,13 @@ async function createInitialDatabase(username, password, theme) {
|
|||||||
isExpanded: true,
|
isExpanded: true,
|
||||||
notePosition: 10
|
notePosition: 10
|
||||||
}).save();
|
}).save();
|
||||||
|
|
||||||
|
const optionsInitService = require('./options_init');
|
||||||
|
|
||||||
|
optionsInitService.initDocumentOptions();
|
||||||
|
optionsInitService.initSyncedOptions(username, password);
|
||||||
|
optionsInitService.initNotSyncedOptions(true, { theme });
|
||||||
|
optionsInitService.initStartupOptions();
|
||||||
});
|
});
|
||||||
|
|
||||||
log.info("Importing demo content ...");
|
log.info("Importing demo content ...");
|
||||||
@ -91,16 +98,20 @@ async function createInitialDatabase(username, password, theme) {
|
|||||||
const zipImportService = require("./import/zip");
|
const zipImportService = require("./import/zip");
|
||||||
await zipImportService.importZip(dummyTaskContext, demoFile, rootNote);
|
await zipImportService.importZip(dummyTaskContext, demoFile, rootNote);
|
||||||
|
|
||||||
log.info("Initializing options ...");
|
|
||||||
|
|
||||||
sql.transactional(() => {
|
sql.transactional(() => {
|
||||||
|
// this needs to happen after ZIP import
|
||||||
|
// previous solution was to move option initialization here but then the important parts of initialization
|
||||||
|
// are not all in one transaction (because ZIP import is async and thus not transactional)
|
||||||
|
|
||||||
const startNoteId = sql.getValue("SELECT noteId FROM branches WHERE parentNoteId = 'root' AND isDeleted = 0 ORDER BY notePosition");
|
const startNoteId = sql.getValue("SELECT noteId FROM branches WHERE parentNoteId = 'root' AND isDeleted = 0 ORDER BY notePosition");
|
||||||
|
|
||||||
const optionsInitService = require('./options_init');
|
const optionService = require("./options");
|
||||||
|
optionService.setOption('openTabs', JSON.stringify([
|
||||||
optionsInitService.initDocumentOptions();
|
{
|
||||||
optionsInitService.initSyncedOptions(username, password);
|
notePath: startNoteId,
|
||||||
optionsInitService.initNotSyncedOptions(true, startNoteId, { theme });
|
active: true
|
||||||
|
}
|
||||||
|
]));
|
||||||
});
|
});
|
||||||
|
|
||||||
log.info("Schema and initial content generated.");
|
log.info("Schema and initial content generated.");
|
||||||
@ -120,7 +131,7 @@ function createDatabaseForSync(options, syncServerHost = '', syncProxy = '') {
|
|||||||
sql.transactional(() => {
|
sql.transactional(() => {
|
||||||
sql.executeScript(schema);
|
sql.executeScript(schema);
|
||||||
|
|
||||||
require('./options_init').initNotSyncedOptions(false, 'root', { syncServerHost, syncProxy });
|
require('./options_init').initNotSyncedOptions(false, { syncServerHost, syncProxy });
|
||||||
|
|
||||||
// document options required for sync to kick off
|
// document options required for sync to kick off
|
||||||
for (const opt of options) {
|
for (const opt of options) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user