consistency checks fixes

This commit is contained in:
zadam 2020-07-01 22:42:59 +02:00
parent f0b608ddec
commit 78a2c1753e
4 changed files with 43 additions and 39 deletions

View File

@ -117,7 +117,6 @@ class Note extends Entity {
return JSON.parse(content); return JSON.parse(content);
} }
/** @returns {Promise} */
setContent(content) { setContent(content) {
if (content === null || content === undefined) { if (content === null || content === undefined) {
throw new Error(`Cannot set null content to note ${this.noteId}`); throw new Error(`Cannot set null content to note ${this.noteId}`);

View File

@ -100,7 +100,6 @@ class NoteRevision extends Entity {
} }
} }
/** @returns {Promise} */
setContent(content) { setContent(content) {
// force updating note itself so that utcDateModified is represented correctly even for the content // force updating note itself so that utcDateModified is represented correctly even for the content
this.forcedChange = true; this.forcedChange = true;

View File

@ -24,7 +24,7 @@ class ConsistencyChecks {
for (const res of results) { for (const res of results) {
try { try {
fixerCb(res); sql.transactional(() => fixerCb(res));
if (this.autoFix) { if (this.autoFix) {
this.fixedIssues = true; this.fixedIssues = true;
@ -605,7 +605,7 @@ class ConsistencyChecks {
this.runSyncRowChecks("options", "name"); this.runSyncRowChecks("options", "name");
} }
runAllChecks() { runAllChecksAndFixers() {
this.unrecoveredConsistencyErrors = false; this.unrecoveredConsistencyErrors = false;
this.fixedIssues = false; this.fixedIssues = false;
@ -639,19 +639,24 @@ class ConsistencyChecks {
} }
runDbDiagnostics() { runDbDiagnostics() {
this.showEntityStat("Notes", `SELECT isDeleted, count(1) this.showEntityStat("Notes",
`SELECT isDeleted, count(1)
FROM notes FROM notes
GROUP BY isDeleted`); GROUP BY isDeleted`);
this.showEntityStat("Note revisions", `SELECT isErased, count(1) this.showEntityStat("Note revisions",
`SELECT isErased, count(1)
FROM note_revisions FROM note_revisions
GROUP BY isErased`); GROUP BY isErased`);
this.showEntityStat("Branches", `SELECT isDeleted, count(1) this.showEntityStat("Branches",
`SELECT isDeleted, count(1)
FROM branches FROM branches
GROUP BY isDeleted`); GROUP BY isDeleted`);
this.showEntityStat("Attributes", `SELECT isDeleted, count(1) this.showEntityStat("Attributes",
`SELECT isDeleted, count(1)
FROM attributes FROM attributes
GROUP BY isDeleted`); GROUP BY isDeleted`);
this.showEntityStat("API tokens", `SELECT isDeleted, count(1) this.showEntityStat("API tokens",
`SELECT isDeleted, count(1)
FROM api_tokens FROM api_tokens
GROUP BY isDeleted`); GROUP BY isDeleted`);
} }
@ -660,13 +665,13 @@ class ConsistencyChecks {
let elapsedTimeMs; let elapsedTimeMs;
await syncMutexService.doExclusively(() => { await syncMutexService.doExclusively(() => {
const startTime = new Date(); const startTimeMs = Date.now();
this.runDbDiagnostics(); this.runDbDiagnostics();
this.runAllChecks(); this.runAllChecksAndFixers();
elapsedTimeMs = Date.now() - startTime.getTime(); elapsedTimeMs = Date.now() - startTimeMs;
}); });
if (this.unrecoveredConsistencyErrors) { if (this.unrecoveredConsistencyErrors) {

View File

@ -158,7 +158,8 @@ function getContentDisposition(filename) {
const STRING_MIME_TYPES = ["application/x-javascript", "image/svg+xml"]; const STRING_MIME_TYPES = ["application/x-javascript", "image/svg+xml"];
function isStringNote(type, mime) { function isStringNote(type, mime) {
return ["text", "code", "relation-map", "search"].includes(type) // render and book are string note in the sense that they are expected to contain empty string
return ["text", "code", "relation-map", "search", "render", "book"].includes(type)
|| mime.startsWith('text/') || mime.startsWith('text/')
|| STRING_MIME_TYPES.includes(mime); || STRING_MIME_TYPES.includes(mime);
} }