mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
becca conversion WIP
This commit is contained in:
parent
6626f100ad
commit
d13c8771ca
@ -5,7 +5,6 @@ const Branch = require('../entities/branch');
|
|||||||
const Attribute = require('../entities/attribute');
|
const Attribute = require('../entities/attribute');
|
||||||
const RecentNote = require('../entities/recent_note');
|
const RecentNote = require('../entities/recent_note');
|
||||||
const ApiToken = require('../entities/api_token');
|
const ApiToken = require('../entities/api_token');
|
||||||
const Option = require('../entities/option');
|
|
||||||
const cls = require('../services/cls');
|
const cls = require('../services/cls');
|
||||||
|
|
||||||
const ENTITY_NAME_TO_ENTITY = {
|
const ENTITY_NAME_TO_ENTITY = {
|
||||||
@ -16,7 +15,6 @@ const ENTITY_NAME_TO_ENTITY = {
|
|||||||
"note_revisions": NoteRevision,
|
"note_revisions": NoteRevision,
|
||||||
"note_revision_contents": NoteRevision,
|
"note_revision_contents": NoteRevision,
|
||||||
"recent_notes": RecentNote,
|
"recent_notes": RecentNote,
|
||||||
"options": Option,
|
|
||||||
"api_tokens": ApiToken,
|
"api_tokens": ApiToken,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -57,9 +55,6 @@ function createEntityFromRow(row) {
|
|||||||
|
|
||||||
cls.setEntityToCache('notes', row.noteId, entity);
|
cls.setEntityToCache('notes', row.noteId, entity);
|
||||||
}
|
}
|
||||||
else if (row.name) {
|
|
||||||
entity = new Option(row);
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
throw new Error('Unknown entity type for row: ' + JSON.stringify(row));
|
throw new Error('Unknown entity type for row: ' + JSON.stringify(row));
|
||||||
}
|
}
|
||||||
|
@ -75,6 +75,10 @@ class Becca {
|
|||||||
|
|
||||||
return row ? new NoteRevision(row) : null;
|
return row ? new NoteRevision(row) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getOption(name) {
|
||||||
|
return this.options[name];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const becca = new Becca();
|
const becca = new Becca();
|
||||||
|
@ -10,8 +10,14 @@ const Branch = require('./entities/branch');
|
|||||||
const Attribute = require('./entities/attribute');
|
const Attribute = require('./entities/attribute');
|
||||||
const Option = require('./entities/option');
|
const Option = require('./entities/option');
|
||||||
|
|
||||||
|
const beccaLoaded = new Promise((res, rej) => {
|
||||||
sqlInit.dbReady.then(() => {
|
sqlInit.dbReady.then(() => {
|
||||||
load();
|
load();
|
||||||
|
|
||||||
|
require('../options_init').initStartupOptions();
|
||||||
|
|
||||||
|
res();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function load() {
|
function load() {
|
||||||
@ -182,5 +188,6 @@ eventService.subscribe(eventService.ENTER_PROTECTED_SESSION, () => {
|
|||||||
eventService.subscribe(eventService.LEAVE_PROTECTED_SESSION, load);
|
eventService.subscribe(eventService.LEAVE_PROTECTED_SESSION, load);
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
load
|
load,
|
||||||
|
beccaLoaded
|
||||||
};
|
};
|
||||||
|
@ -26,6 +26,8 @@ class Option extends AbstractEntity {
|
|||||||
super.beforeSaving();
|
super.beforeSaving();
|
||||||
|
|
||||||
this.utcDateModified = dateUtils.utcNowDateTime();
|
this.utcDateModified = dateUtils.utcNowDateTime();
|
||||||
|
// utcDateCreated is scheduled for removal so the value does not matter
|
||||||
|
this.utcDateCreated = dateUtils.utcNowDateTime();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,13 +3,6 @@
|
|||||||
const sql = require('./sql');
|
const sql = require('./sql');
|
||||||
const utils = require('./utils');
|
const utils = require('./utils');
|
||||||
const log = require('./log');
|
const log = require('./log');
|
||||||
const ApiToken = require('../entities/api_token');
|
|
||||||
const Branch = require('../entities/branch');
|
|
||||||
const Note = require('../entities/note');
|
|
||||||
const Attribute = require('../entities/attribute');
|
|
||||||
const NoteRevision = require('./becca/entities/note_revision.js');
|
|
||||||
const RecentNote = require('../entities/recent_note');
|
|
||||||
const Option = require('../entities/option');
|
|
||||||
|
|
||||||
function getSectorHashes(tableName, primaryKeyName, whereBranch) {
|
function getSectorHashes(tableName, primaryKeyName, whereBranch) {
|
||||||
const hashes = sql.getRows(`SELECT ${primaryKeyName} AS id, hash FROM ${tableName}`
|
const hashes = sql.getRows(`SELECT ${primaryKeyName} AS id, hash FROM ${tableName}`
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
|
const becca = require('./becca/becca');
|
||||||
|
|
||||||
function getOption(name) {
|
function getOption(name) {
|
||||||
const option = require('./becca').getOption(name);
|
const option = require('./becca/becca').getOption(name);
|
||||||
|
|
||||||
if (!option) {
|
if (!option) {
|
||||||
throw new Error(`Option ${name} doesn't exist`);
|
throw new Error(`Option "${name}" doesn't exist`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return option.value;
|
return option.value;
|
||||||
@ -37,7 +39,7 @@ function getOptionBool(name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setOption(name, value) {
|
function setOption(name, value) {
|
||||||
const option = require('./becca').getOption(name);
|
const option = becca.getOption(name);
|
||||||
|
|
||||||
if (value === true || value === false) {
|
if (value === true || value === false) {
|
||||||
value = value.toString();
|
value = value.toString();
|
||||||
@ -65,11 +67,17 @@ function createOption(name, value, isSynced) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getOptions() {
|
function getOptions() {
|
||||||
return require('./repository').getEntities("SELECT * FROM options ORDER BY name");
|
return Object.values(becca.options);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getOptionsMap() {
|
function getOptionsMap() {
|
||||||
return require('./sql').getMap("SELECT name, value FROM options ORDER BY name");
|
const map = {};
|
||||||
|
|
||||||
|
for (const option of Object.values(becca.options)) {
|
||||||
|
map[option.name] = option.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -5,7 +5,7 @@ const sql = require('./sql');
|
|||||||
const utils = require('./utils');
|
const utils = require('./utils');
|
||||||
const optionService = require('./options');
|
const optionService = require('./options');
|
||||||
const port = require('./port');
|
const port = require('./port');
|
||||||
const Option = require('../entities/option');
|
const Option = require('./becca/entities/option');
|
||||||
const TaskContext = require('./task_context.js');
|
const TaskContext = require('./task_context.js');
|
||||||
const migrationService = require('./migration');
|
const migrationService = require('./migration');
|
||||||
const cls = require('./cls');
|
const cls = require('./cls');
|
||||||
@ -39,8 +39,6 @@ async function initDbConnection() {
|
|||||||
|
|
||||||
await migrationService.migrateIfNecessary();
|
await migrationService.migrateIfNecessary();
|
||||||
|
|
||||||
require('./options_init').initStartupOptions();
|
|
||||||
|
|
||||||
sql.execute('CREATE TEMP TABLE "param_list" (`paramId` TEXT NOT NULL PRIMARY KEY)');
|
sql.execute('CREATE TEMP TABLE "param_list" (`paramId` TEXT NOT NULL PRIMARY KEY)');
|
||||||
|
|
||||||
dbReady.resolve();
|
dbReady.resolve();
|
||||||
|
@ -383,17 +383,15 @@ function getOutstandingPullCount() {
|
|||||||
return outstandingPullCount;
|
return outstandingPullCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlInit.dbReady.then(() => {
|
require("./becca/becca_loader").beccaLoaded.then(() => {
|
||||||
setInterval(cls.wrap(sync), 60000);
|
setInterval(cls.wrap(sync), 60000);
|
||||||
|
|
||||||
// kickoff initial sync immediately
|
// kickoff initial sync immediately
|
||||||
setTimeout(cls.wrap(sync), 5000);
|
setTimeout(cls.wrap(sync), 5000);
|
||||||
});
|
|
||||||
|
|
||||||
if (sqlInit.isDbInitialized()) {
|
|
||||||
// called just so ws.setLastSyncedPush() is called
|
// called just so ws.setLastSyncedPush() is called
|
||||||
getLastSyncedPush();
|
getLastSyncedPush();
|
||||||
}
|
});
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
sync,
|
sync,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user