mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
introduced 'autoFixConsistencyIssues' option to control whether consistency issues should be auto fixed or note
This commit is contained in:
parent
8f2d2b189c
commit
466a4802b6
@ -8,9 +8,10 @@ const syncMutexService = require('./sync_mutex');
|
|||||||
const repository = require('./repository');
|
const repository = require('./repository');
|
||||||
const cls = require('./cls');
|
const cls = require('./cls');
|
||||||
const syncTableService = require('./sync_table');
|
const syncTableService = require('./sync_table');
|
||||||
|
const optionsService = require('./options');
|
||||||
const Branch = require('../entities/branch');
|
const Branch = require('../entities/branch');
|
||||||
|
|
||||||
let unrecoverableConsistencyErrors = false;
|
let unrecoveredConsistencyErrors = false;
|
||||||
let fixedIssues = false;
|
let fixedIssues = false;
|
||||||
|
|
||||||
async function findIssues(query, errorCb) {
|
async function findIssues(query, errorCb) {
|
||||||
@ -19,7 +20,7 @@ async function findIssues(query, errorCb) {
|
|||||||
for (const res of results) {
|
for (const res of results) {
|
||||||
logError(errorCb(res));
|
logError(errorCb(res));
|
||||||
|
|
||||||
unrecoverableConsistencyErrors = true;
|
unrecoveredConsistencyErrors = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
@ -29,9 +30,14 @@ async function findAndFixIssues(query, fixerCb) {
|
|||||||
const results = await sql.getRows(query);
|
const results = await sql.getRows(query);
|
||||||
|
|
||||||
for (const res of results) {
|
for (const res of results) {
|
||||||
await fixerCb(res);
|
if (await optionsService.getOptionInt('autoFixConsistencyIssues')) {
|
||||||
|
await fixerCb(res);
|
||||||
|
|
||||||
fixedIssues = true;
|
fixedIssues = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
unrecoveredConsistencyErrors = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
@ -57,7 +63,7 @@ async function checkTreeCycles() {
|
|||||||
if (!childToParents[noteId] || childToParents[noteId].length === 0) {
|
if (!childToParents[noteId] || childToParents[noteId].length === 0) {
|
||||||
logError(`No parents found for note ${noteId}`);
|
logError(`No parents found for note ${noteId}`);
|
||||||
|
|
||||||
unrecoverableConsistencyErrors = true;
|
unrecoveredConsistencyErrors = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,7 +71,7 @@ async function checkTreeCycles() {
|
|||||||
if (path.includes(parentNoteId)) {
|
if (path.includes(parentNoteId)) {
|
||||||
logError(`Tree cycle detected at parent-child relationship: ${parentNoteId} - ${noteId}, whole path: ${path}`);
|
logError(`Tree cycle detected at parent-child relationship: ${parentNoteId} - ${noteId}, whole path: ${path}`);
|
||||||
|
|
||||||
unrecoverableConsistencyErrors = true;
|
unrecoveredConsistencyErrors = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const newPath = path.slice();
|
const newPath = path.slice();
|
||||||
@ -84,7 +90,7 @@ async function checkTreeCycles() {
|
|||||||
|
|
||||||
if (childToParents['root'].length !== 1 || childToParents['root'][0] !== 'none') {
|
if (childToParents['root'].length !== 1 || childToParents['root'][0] !== 'none') {
|
||||||
logError('Incorrect root parent: ' + JSON.stringify(childToParents['root']));
|
logError('Incorrect root parent: ' + JSON.stringify(childToParents['root']));
|
||||||
unrecoverableConsistencyErrors = true;
|
unrecoveredConsistencyErrors = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -366,7 +372,7 @@ async function findSyncRowsIssues() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function runAllChecks() {
|
async function runAllChecks() {
|
||||||
unrecoverableConsistencyErrors = false;
|
unrecoveredConsistencyErrors = false;
|
||||||
fixedIssues = false;
|
fixedIssues = false;
|
||||||
|
|
||||||
await findBrokenReferenceIssues();
|
await findBrokenReferenceIssues();
|
||||||
@ -377,13 +383,13 @@ async function runAllChecks() {
|
|||||||
|
|
||||||
await findSyncRowsIssues();
|
await findSyncRowsIssues();
|
||||||
|
|
||||||
if (unrecoverableConsistencyErrors) {
|
if (unrecoveredConsistencyErrors) {
|
||||||
// we run this only if basic checks passed since this assumes basic data consistency
|
// we run this only if basic checks passed since this assumes basic data consistency
|
||||||
|
|
||||||
await checkTreeCycles();
|
await checkTreeCycles();
|
||||||
}
|
}
|
||||||
|
|
||||||
return !unrecoverableConsistencyErrors;
|
return !unrecoveredConsistencyErrors;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function runChecks() {
|
async function runChecks() {
|
||||||
@ -401,7 +407,7 @@ async function runChecks() {
|
|||||||
ws.refreshTree();
|
ws.refreshTree();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unrecoverableConsistencyErrors) {
|
if (unrecoveredConsistencyErrors) {
|
||||||
log.info(`Consistency checks failed (took ${elapsedTimeMs}ms)`);
|
log.info(`Consistency checks failed (took ${elapsedTimeMs}ms)`);
|
||||||
|
|
||||||
ws.sendMessageToAllClients({type: 'consistency-checks-failed'});
|
ws.sendMessageToAllClients({type: 'consistency-checks-failed'});
|
||||||
|
@ -10,6 +10,9 @@ async function getOption(name) {
|
|||||||
return option.value;
|
return option.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {Promise<number>}
|
||||||
|
*/
|
||||||
async function getOptionInt(name) {
|
async function getOptionInt(name) {
|
||||||
const val = await getOption(name);
|
const val = await getOption(name);
|
||||||
|
|
||||||
@ -22,6 +25,19 @@ async function getOptionInt(name) {
|
|||||||
return intVal;
|
return intVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {Promise<boolean>}
|
||||||
|
*/
|
||||||
|
async function getOptionBool(name) {
|
||||||
|
const val = await getOption(name);
|
||||||
|
|
||||||
|
if (!['true', 'false'].includes(val)) {
|
||||||
|
throw new Error(`Could not parse "${val}" into boolean for option "${name}"`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return val === 'true';
|
||||||
|
}
|
||||||
|
|
||||||
async function setOption(name, value) {
|
async function setOption(name, value) {
|
||||||
const option = await require('./repository').getOption(name);
|
const option = await require('./repository').getOption(name);
|
||||||
|
|
||||||
@ -64,6 +80,7 @@ async function getOptionsMap(allowedOptions) {
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
getOption,
|
getOption,
|
||||||
getOptionInt,
|
getOptionInt,
|
||||||
|
getOptionBool,
|
||||||
setOption,
|
setOption,
|
||||||
createOption,
|
createOption,
|
||||||
getOptions,
|
getOptions,
|
||||||
|
@ -78,7 +78,8 @@ const defaultOptions = [
|
|||||||
{ name: 'spellCheckLanguageCode', value: 'en-US', isSynced: false },
|
{ name: 'spellCheckLanguageCode', value: 'en-US', isSynced: false },
|
||||||
{ name: 'hideTabRowForOneTab', value: 'false', isSynced: false },
|
{ name: 'hideTabRowForOneTab', value: 'false', isSynced: false },
|
||||||
{ name: 'imageMaxWidthHeight', value: '1200', isSynced: true },
|
{ name: 'imageMaxWidthHeight', value: '1200', isSynced: true },
|
||||||
{ name: 'imageJpegQuality', value: '75', isSynced: true }
|
{ name: 'imageJpegQuality', value: '75', isSynced: true },
|
||||||
|
{ name: 'autoFixConsistencyIssues', value: 'true', isSynced: false }
|
||||||
];
|
];
|
||||||
|
|
||||||
async function initStartupOptions() {
|
async function initStartupOptions() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user