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);
}
/** @returns {Promise} */
setContent(content) {
if (content === null || content === undefined) {
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) {
// force updating note itself so that utcDateModified is represented correctly even for the content
this.forcedChange = true;

View file

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

View file

@ -158,7 +158,8 @@ function getContentDisposition(filename) {
const STRING_MIME_TYPES = ["application/x-javascript", "image/svg+xml"];
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/')
|| STRING_MIME_TYPES.includes(mime);
}