Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
always autofix note_contents.content = NULL sync issue after note erasion
zadamad7a55d30564
diff --git a/.idea/dataSources.xml b/.idea/dataSources.xmlindex 69c5fd8e8a..caa742fa50 100644--- a/.idea/dataSources.xml+++ b/.idea/dataSources.xml@@ -6,9 +6,6 @@<synchronize>true</synchronize><jdbc-driver>org.sqlite.JDBC</jdbc-driver><jdbc-url>jdbc:sqlite:$PROJECT_DIR$/../trilium-data/document.db</jdbc-url>- <driver-properties>- <property name="enable_load_extension" value="true" />- </driver-properties></data-source></component></project>\ No newline at end of filediff --git a/package-lock.json b/package-lock.jsonindex c34def86c1..6eec5f662a 100644--- a/package-lock.json+++ b/package-lock.json@@ -1,6 +1,6 @@{"name": "trilium",- "version": "0.40.2",+ "version": "0.40.3","lockfileVersion": 1,"requires": true,"dependencies": {diff --git a/src/services/consistency_checks.js b/src/services/consistency_checks.jsindex 2a2911b3fc..871706a11f 100644--- a/src/services/consistency_checks.js+++ b/src/services/consistency_checks.js@@ -323,14 +323,25 @@ class ConsistencyChecks {WHERE isErased = 1AND content IS NOT NULL`,async ({noteId}) => {- if (this.autoFix) {- await sql.execute(`UPDATE note_contents SET content = NULL WHERE noteId = ?`, [noteId]);- logFix(`Note ${noteId} content has been set to null since the note is erased`);- }- else {- logError(`Note ${noteId} content is not null even though the note is erased`);- }+ // we always fix this issue because there does not seem to be a good way to prevent it.+ // Scenario in which this can happen:+ // 1. user on instance A deletes the note (sync for notes is created, but not for note_contents) and is later erased+ // 2. instance B gets synced from instance A, note is updated because of sync row for notes,+ // but note_contents is not because erasion does not create sync rows+ // 3. therefore note.isErased = true, but note_contents.content remains not updated and not erased.+ //+ // Considered solutions:+ // - don't sync erased notes - this might prevent syncing also of the isDeleted flag and note would continue+ // to exist on the other instance+ // - create sync rows for erased event - this would be a problem for undeletion since erasion might happen+ // on one instance after undelete and thus would win even though there's no user action behind it+ //+ // So instead we just fix such cases afterwards here.++ await sql.execute(`UPDATE note_contents SET content = NULL WHERE noteId = ?`, [noteId]);++ logFix(`Note ${noteId} content has been set to null since the note is erased`);});await this.findAndFixIssues(`@@ -547,23 +558,23 @@ class ConsistencyChecks {});await this.findAndFixIssues(`- SELECT- id, entityId- FROM- sync- LEFT JOIN ${entityName} ON entityId = ${key}- WHERE- sync.entityName = '${entityName}'- AND ${key} IS NULL`,- async ({id, entityId}) => {- if (this.autoFix) {- await sql.execute("DELETE FROM sync WHERE entityName = ? AND entityId = ?", [entityName, entityId]);-- logFix(`Deleted extra sync record id=${id}, entityName=${entityName}, entityId=${entityId}`);- } else {- logError(`Unrecognized sync record id=${id}, entityName=${entityName}, entityId=${entityId}`);- }- });+ SELECT+ id, entityId+ FROM+ sync+ LEFT JOIN ${entityName} ON entityId = ${key}+ WHERE+ sync.entityName = '${entityName}'+ AND ${key} IS NULL`,+ async ({id, entityId}) => {+ if (this.autoFix) {+ await sql.execute("DELETE FROM sync WHERE entityName = ? AND entityId = ?", [entityName, entityId]);++ logFix(`Deleted extra sync record id=${id}, entityName=${entityName}, entityId=${entityId}`);+ } else {+ logError(`Unrecognized sync record id=${id}, entityName=${entityName}, entityId=${entityId}`);+ }+ });}async findSyncRowsIssues() {diff --git a/src/services/notes.js b/src/services/notes.jsindex ffafb4bb68..068ad0536b 100644--- a/src/services/notes.js+++ b/src/services/notes.js@@ -599,6 +599,7 @@ async function eraseDeletedNotes() {UPDATE notesSET title = '[deleted]',contentLength = 0,+ isProtected = 0,isErased = 1WHERE noteId IN (???)`, noteIdsToErase);