auto init of special notes after startup

This commit is contained in:
zadam 2021-09-16 22:20:59 +02:00
parent 06bcfe1aee
commit 5866004e23
2 changed files with 25 additions and 15 deletions

View File

@ -5,6 +5,7 @@ const config = require('./config');
const log = require('./log');
const sql = require("./sql");
const becca = require("../becca/becca");
const specialNotesService = require("../services/special_notes");
function getRunAtHours(note) {
try {
@ -55,5 +56,7 @@ sqlInit.dbReady.then(() => {
setInterval(cls.wrap(() => runNotesWithLabel('hourly')), 3600 * 1000);
setInterval(cls.wrap(() => runNotesWithLabel('daily')), 24 * 3600 * 1000);
setTimeout(cls.wrap(() => specialNotesService.createMissingSpecialNotes()), 10 * 1000);
}
});

View File

@ -65,20 +65,20 @@ function getSearchRoot() {
return searchRoot;
}
function getSpecialNoteRoot() {
let specialNoteRoot = becca.getNote('special');
function getSinglesNoteRoot() {
let singlesNoteRoot = becca.getNote('singles');
if (!specialNoteRoot) {
specialNoteRoot = noteService.createNewNote({
noteId: 'special',
title: 'special',
if (!singlesNoteRoot) {
singlesNoteRoot = noteService.createNewNote({
noteId: 'singles',
title: 'singles',
type: 'text',
content: '',
parentNoteId: getHiddenRoot().noteId
}).note;
}
return specialNoteRoot;
return singlesNoteRoot;
}
function getGlobalLinkMapNote() {
@ -90,7 +90,7 @@ function getGlobalLinkMapNote() {
title: 'global-link-map',
type: 'global-link-map',
content: '',
parentNoteId: getSpecialNoteRoot().noteId
parentNoteId: getSinglesNoteRoot().noteId
}).note;
}
@ -138,13 +138,7 @@ function saveSqlConsole(sqlConsoleNoteId) {
return sqlConsoleNote.cloneTo(sqlConsoleHome.noteId);
}
function getHoistedNote() {
return becca.getNote(cls.getHoistedNoteId());
}
function createSearchNote(searchString, ancestorNoteId) {
const hoistedNote = getHoistedNote();
const {note} = noteService.createNewNote({
parentNoteId: getSearchRoot().noteId,
title: 'Search: ' + searchString,
@ -183,10 +177,23 @@ function saveSearchNote(searchNoteId) {
return searchNote.cloneTo(searchHome.noteId);
}
function getHoistedNote() {
return becca.getNote(cls.getHoistedNoteId());
}
function createMissingSpecialNotes() {
getSinglesNoteRoot();
getSqlConsoleRoot();
getSinglesNoteRoot();
getSinglesNoteRoot();
getGlobalLinkMapNote();
}
module.exports = {
getInboxNote,
createSqlConsole,
saveSqlConsole,
createSearchNote,
saveSearchNote
saveSearchNote,
createMissingSpecialNotes
};