mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
fix interrupted initial sync
This commit is contained in:
parent
5ecb603e86
commit
003fec4b11
@ -1,7 +1,16 @@
|
|||||||
const becca = require('../becca/becca');
|
const becca = require('../becca/becca');
|
||||||
|
const sql = require("./sql.js");
|
||||||
|
|
||||||
function getOption(name) {
|
function getOption(name) {
|
||||||
const option = require('../becca/becca').getOption(name);
|
let option;
|
||||||
|
|
||||||
|
if (becca.loaded) {
|
||||||
|
option = becca.getOption(name);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// e.g. in initial sync becca is not loaded because DB is not initialized
|
||||||
|
option = sql.getRow("SELECT * FROM options WHERE name = ?", name);
|
||||||
|
}
|
||||||
|
|
||||||
if (!option) {
|
if (!option) {
|
||||||
throw new Error(`Option "${name}" doesn't exist`);
|
throw new Error(`Option "${name}" doesn't exist`);
|
||||||
@ -39,12 +48,12 @@ function getOptionBool(name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setOption(name, value) {
|
function setOption(name, value) {
|
||||||
const option = becca.getOption(name);
|
|
||||||
|
|
||||||
if (value === true || value === false) {
|
if (value === true || value === false) {
|
||||||
value = value.toString();
|
value = value.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const option = becca.getOption(name);
|
||||||
|
|
||||||
if (option) {
|
if (option) {
|
||||||
option.value = value;
|
option.value = value;
|
||||||
|
|
||||||
|
@ -371,7 +371,10 @@ function getLastSyncedPull() {
|
|||||||
|
|
||||||
function setLastSyncedPull(entityChangeId) {
|
function setLastSyncedPull(entityChangeId) {
|
||||||
const lastSyncedPullOption = becca.getOption('lastSyncedPull');
|
const lastSyncedPullOption = becca.getOption('lastSyncedPull');
|
||||||
lastSyncedPullOption.value = entityChangeId + '';
|
|
||||||
|
if (lastSyncedPullOption) { // might be null in initial sync when becca is not loaded
|
||||||
|
lastSyncedPullOption.value = entityChangeId + '';
|
||||||
|
}
|
||||||
|
|
||||||
// this way we avoid updating entity_changes which otherwise means that we've never pushed all entity_changes
|
// this way we avoid updating entity_changes which otherwise means that we've never pushed all entity_changes
|
||||||
sql.execute("UPDATE options SET value = ? WHERE name = ?", [entityChangeId, 'lastSyncedPull']);
|
sql.execute("UPDATE options SET value = ? WHERE name = ?", [entityChangeId, 'lastSyncedPull']);
|
||||||
@ -389,7 +392,10 @@ function setLastSyncedPush(entityChangeId) {
|
|||||||
ws.setLastSyncedPush(entityChangeId);
|
ws.setLastSyncedPush(entityChangeId);
|
||||||
|
|
||||||
const lastSyncedPushOption = becca.getOption('lastSyncedPush');
|
const lastSyncedPushOption = becca.getOption('lastSyncedPush');
|
||||||
lastSyncedPushOption.value = entityChangeId + '';
|
|
||||||
|
if (lastSyncedPushOption) { // might be null in initial sync when becca is not loaded
|
||||||
|
lastSyncedPushOption.value = entityChangeId + '';
|
||||||
|
}
|
||||||
|
|
||||||
// this way we avoid updating entity_changes which otherwise means that we've never pushed all entity_changes
|
// this way we avoid updating entity_changes which otherwise means that we've never pushed all entity_changes
|
||||||
sql.execute("UPDATE options SET value = ? WHERE name = ?", [entityChangeId, 'lastSyncedPush']);
|
sql.execute("UPDATE options SET value = ? WHERE name = ?", [entityChangeId, 'lastSyncedPush']);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user