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
consistency_checks fix
zadam4023c28f5e7b
diff --git a/package-lock.json b/package-lock.jsonindex 0082d24eb0..2e7aa841f2 100644--- a/package-lock.json+++ b/package-lock.json@@ -1602,22 +1602,22 @@"integrity": "sha512-9o5UecI3GhkpM6DrXr69PblIuWxPKk9Y0jHBRhdocZ2y7YECBFCsHm79Pr3OyR2AvjhDkabFJaDJMYRazHgsow=="},"browserslist": {- "version": "4.16.8",- "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.16.8.tgz",- "integrity": "sha512-sc2m9ohR/49sWEbPj14ZSSZqp+kbi16aLao42Hmn3Z8FpjuMaq2xCA2l4zl9ITfyzvnvyE0hcg62YkIGKxgaNQ==",+ "version": "4.17.0",+ "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.17.0.tgz",+ "integrity": "sha512-g2BJ2a0nEYvEFQC208q8mVAhfNwpZ5Mu8BwgtCdZKO3qx98HChmeg448fPdUzld8aFmfLgVh7yymqV+q1lJZ5g==","dev": true,"requires": {- "caniuse-lite": "^1.0.30001251",+ "caniuse-lite": "^1.0.30001254","colorette": "^1.3.0",- "electron-to-chromium": "^1.3.811",+ "electron-to-chromium": "^1.3.830","escalade": "^3.1.1","node-releases": "^1.1.75"},"dependencies": {"colorette": {- "version": "1.3.0",- "resolved": "https://registry.npmjs.org/colorette/-/colorette-1.3.0.tgz",- "integrity": "sha512-ecORCqbSFP7Wm8Y6lyqMJjexBQqXSF7SSeaTyGGphogUjBlFP9m9o08wy86HL2uB7fMTxtOUzLMk7ogKcxMg1w==",+ "version": "1.4.0",+ "resolved": "https://registry.npmjs.org/colorette/-/colorette-1.4.0.tgz",+ "integrity": "sha512-Y2oEozpomLn7Q3HFP7dpww7AtMJplbM9lGZP6RDfHqmbeRjiwRg4n6VM6j4KLmRke85uWEI7JqF17f3pqdRA0g==","dev": true}}@@ -1899,9 +1899,9 @@"dev": true},"caniuse-lite": {- "version": "1.0.30001254",- "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001254.tgz",- "integrity": "sha512-GxeHOvR0LFMYPmFGA+NiTOt9uwYDxB3h154tW2yBYwfz2EMX3i1IBgr6gmJGfU0K8KQsqPa5XqLD8zVdP5lUzA==",+ "version": "1.0.30001256",+ "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001256.tgz",+ "integrity": "sha512-QirrvMLmB4txNnxiaG/xbm6FSzv9LqOZ3Jp9VtCYb3oPIfCHpr/oGn38pFq0udwlkctvXQgPthaXqJ76DaYGnA==","dev": true},"caseless": {@@ -2532,9 +2532,9 @@}},"dayjs": {- "version": "1.10.6",- "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.10.6.tgz",- "integrity": "sha512-AztC/IOW4L1Q41A86phW5Thhcrco3xuAA+YX/BLpLWWjRcTj5TOt/QImBLmCKlrF7u7k47arTnOyL6GnbG8Hvw=="+ "version": "1.10.7",+ "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.10.7.tgz",+ "integrity": "sha512-P6twpd70BcPK34K26uJ1KT3wlhpuOAPoMwJzpsIWUxHZ7wpmbdZL/hQqBDfz7hGurYSa5PhzdhDHtt319hL3ig=="},"debug": {"version": "4.1.1",@@ -3177,9 +3177,9 @@}},"electron-notarize": {- "version": "1.0.0",- "resolved": "https://registry.npmjs.org/electron-notarize/-/electron-notarize-1.0.0.tgz",- "integrity": "sha512-dsib1IAquMn0onCrNMJ6gtEIZn/azG8hZMCYOuZIMVMUeRMgBYHK1s5TK9P8xAcrAjh/2aN5WYHzgVSWX314og==",+ "version": "1.1.1",+ "resolved": "https://registry.npmjs.org/electron-notarize/-/electron-notarize-1.1.1.tgz",+ "integrity": "sha512-kufsnqh86CTX89AYNG3NCPoboqnku/+32RxeJ2+7A4Rbm4bbOx0Nc7XTy3/gAlBfpj9xPAxHfhZLOHgfi6cJVw==","dev": true,"requires": {"debug": "^4.1.1",@@ -3251,16 +3251,16 @@}},"electron-packager": {- "version": "15.3.0",- "resolved": "https://registry.npmjs.org/electron-packager/-/electron-packager-15.3.0.tgz",- "integrity": "sha512-PHcykXinmjPyJcYoNGbOWNsOU25nIbMLHBAfg4caazWzYELFL14FshDZEqqrvVOMEUnqjx/Ktc1NmMIN5ZRomQ==",+ "version": "15.4.0",+ "resolved": "https://registry.npmjs.org/electron-packager/-/electron-packager-15.4.0.tgz",+ "integrity": "sha512-JrrLcBP15KGrPj0cZ/ALKGmaQ4gJkn3mocf0E3bRKdR3kxKWYcDRpCvdhksYDXw/r3I6tMEcZ7XzyApWFXdVpw==","dev": true,"requires": {"@electron/get": "^1.6.0",- "asar": "^3.0.0",+ "asar": "^3.1.0","cross-spawn-windows-exe": "^1.2.0","debug": "^4.0.1",- "electron-notarize": "^1.0.0",+ "electron-notarize": "^1.1.1","electron-osx-sign": "^0.5.0","extract-zip": "^2.0.0","filenamify": "^4.1.0",@@ -3276,6 +3276,19 @@"yargs-parser": "^20.0.0"},"dependencies": {+ "asar": {+ "version": "3.1.0",+ "resolved": "https://registry.npmjs.org/asar/-/asar-3.1.0.tgz",+ "integrity": "sha512-vyxPxP5arcAqN4F/ebHd/HhwnAiZtwhglvdmc7BR2f0ywbVNTOpSeyhLDbGXtE/y58hv1oC75TaNIXutnsOZsQ==",+ "dev": true,+ "requires": {+ "@types/glob": "^7.1.1",+ "chromium-pickle-js": "^0.2.0",+ "commander": "^5.0.0",+ "glob": "^7.1.6",+ "minimatch": "^3.0.4"+ }+ },"cross-spawn-windows-exe": {"version": "1.2.0","resolved": "https://registry.npmjs.org/cross-spawn-windows-exe/-/cross-spawn-windows-exe-1.2.0.tgz",@@ -3573,9 +3586,9 @@}},"electron-to-chromium": {- "version": "1.3.830",- "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.830.tgz",- "integrity": "sha512-gBN7wNAxV5vl1430dG+XRcQhD4pIeYeak6p6rjdCtlz5wWNwDad8jwvphe5oi1chL5MV6RNRikfffBBiFuj+rQ==",+ "version": "1.3.836",+ "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.836.tgz",+ "integrity": "sha512-Ney3pHOJBWkG/AqYjrW0hr2AUCsao+2uvq9HUlRP8OlpSdk/zOHOUJP7eu0icDvePC9DlgffuelP4TnOJmMRUg==","dev": true},"electron-window-state": {@@ -4983,9 +4996,9 @@"dev": true},"jest-worker": {- "version": "27.1.0",- "resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-27.1.0.tgz",- "integrity": "sha512-mO4PHb2QWLn9yRXGp7rkvXLAYuxwhq1ZYUo0LoDhg8wqvv4QizP1ZWEJOeolgbEgAWZLIEU0wsku8J+lGWfBhg==",+ "version": "27.1.1",+ "resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-27.1.1.tgz",+ "integrity": "sha512-XJKCL7tu+362IUYTWvw8+3S75U7qMiYiRU6u5yqscB48bTvzwN6i8L/7wVTXiFLwkRsxARNM7TISnTvcgv9hxA==","dev": true,"requires": {"@types/node": "*",@@ -5779,9 +5792,9 @@}},"nanoid": {- "version": "3.1.23",- "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.1.23.tgz",- "integrity": "sha512-FiB0kzdP0FFVGDKlRLEQ1BgDzU87dy5NnzjeW9YZNt+/c3+q82EQDUwniSAUxp/F0gFNI1ZhKU1FqYsMuqZVnw=="+ "version": "3.1.25",+ "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.1.25.tgz",+ "integrity": "sha512-rdwtIXaXCLFAQbnfqDRnI6jaRHp9fTcYBjtFKE8eezcZ7LuLjhUaQGNeMXf1HmRoCH32CLz6XwX0TtxEOS/A3Q=="},"napi-build-utils": {"version": "1.0.2",@@ -6378,9 +6391,9 @@}},"postcss": {- "version": "8.3.0",- "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.3.0.tgz",- "integrity": "sha512-+ogXpdAjWGa+fdYY5BQ96V/6tAo+TdSSIMP5huJBIygdWwKtVoB5JWZ7yUd4xZ8r+8Kvvx4nyg/PQ071H4UtcQ==",+ "version": "8.3.6",+ "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.3.6.tgz",+ "integrity": "sha512-wG1cc/JhRgdqB6WHEuyLTedf3KIRuD0hG6ldkFEZNCjRxiC+3i6kkWUUbiJQayP28iwG35cEmAbe98585BYV0A==","requires": {"colorette": "^1.2.2","nanoid": "^3.1.23",@@ -6860,9 +6873,9 @@}},"sanitize-html": {- "version": "2.4.0",- "resolved": "https://registry.npmjs.org/sanitize-html/-/sanitize-html-2.4.0.tgz",- "integrity": "sha512-Y1OgkUiTPMqwZNRLPERSEi39iOebn2XJLbeiGOBhaJD/yLqtLGu6GE5w7evx177LeGgSE+4p4e107LMiydOf6A==",+ "version": "2.5.0",+ "resolved": "https://registry.npmjs.org/sanitize-html/-/sanitize-html-2.5.0.tgz",+ "integrity": "sha512-smU67ODza8E0rJF7oY37qQqMF5srxwEkqsgV17PFfdYAtIxnicH8LIyDEGINJIso8bPaxRZS7zGhCjg6BeDoqQ==","requires": {"deepmerge": "^4.2.2","escape-string-regexp": "^4.0.0",@@ -6889,17 +6902,17 @@"integrity": "sha512-DtBMo82pv1dFtUmHyr48beiuq792Sxohr+8Hm9zoxklYPfa6n0Z3Byjj2IV7bmr2IyqClnqEQhfgHJJ5QF0R5A=="},"domhandler": {- "version": "4.2.0",- "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-4.2.0.tgz",- "integrity": "sha512-zk7sgt970kzPks2Bf+dwT/PLzghLnsivb9CcxkvR8Mzr66Olr0Ofd8neSbglHJHaHa2MadfoSdNlKYAaafmWfA==",+ "version": "4.2.2",+ "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-4.2.2.tgz",+ "integrity": "sha512-PzE9aBMsdZO8TK4BnuJwH0QT41wgMbRzuZrHUcpYncEjmQazq8QEaBWgLG7ZyC/DAZKEgglpIA6j4Qn/HmxS3w==","requires": {"domelementtype": "^2.2.0"}},"domutils": {- "version": "2.6.0",- "resolved": "https://registry.npmjs.org/domutils/-/domutils-2.6.0.tgz",- "integrity": "sha512-y0BezHuy4MDYxh6OvolXYsH+1EMGmFbwv5FKW7ovwMG6zTPWqNPq3WF9ayZssFq+UlKdffGLbOEaghNdaOm1WA==",+ "version": "2.8.0",+ "resolved": "https://registry.npmjs.org/domutils/-/domutils-2.8.0.tgz",+ "integrity": "sha512-w96Cjofp72M5IIhpjgobBimYEfoPjx1Vx0BSX9P30WBdZW2WIKU0T1Bd0kz2eNZ9ikjKgHbEyKx8BB6H1L3h3A==","requires": {"dom-serializer": "^1.0.1","domelementtype": "^2.2.0",@@ -7316,9 +7329,9 @@}},"spdx-license-ids": {- "version": "3.0.9",- "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.9.tgz",- "integrity": "sha512-Ki212dKK4ogX+xDo4CtOZBVIwhsKBEfsEEcwmJfLQzirgc2jIWdzg40Unxz/HzEUqM1WFzVlQSMF9kZZ2HboLQ==",+ "version": "3.0.10",+ "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.10.tgz",+ "integrity": "sha512-oie3/+gKf7QtpitB0LYLETe+k8SifzsX4KixvpOsbI6S0kRiRQ5MKOio8eMSAKQ17N06+wdEOXRiId+zOxo0hA==","dev": true},"sprintf-js": {@@ -7573,9 +7586,9 @@}},"terser-webpack-plugin": {- "version": "5.2.3",- "resolved": "https://registry.npmjs.org/terser-webpack-plugin/-/terser-webpack-plugin-5.2.3.tgz",- "integrity": "sha512-eDbuaDlXhVaaoKuLD3DTNTozKqln6xOG6Us0SzlKG5tNlazG+/cdl8pm9qiF1Di89iWScTI0HcO+CDcf2dkXiw==",+ "version": "5.2.4",+ "resolved": "https://registry.npmjs.org/terser-webpack-plugin/-/terser-webpack-plugin-5.2.4.tgz",+ "integrity": "sha512-E2CkNMN+1cho04YpdANyRrn8CyN4yMy+WdFKZIySFZrGXZxJwJP6PMNGGc/Mcr6qygQHUUqRxnAPmi0M9f00XA==","dev": true,"requires": {"jest-worker": "^27.0.6",@@ -8028,9 +8041,9 @@"integrity": "sha512-qBIvFLGiBpLjfwmYAaHPXsn+ho5xZnGvyGvsarywGNc8VyQJUMHJ8OBKGGrPER0okBeMDaan4mNBlgBROxuI8w=="},"webpack": {- "version": "5.52.0",- "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.52.0.tgz",- "integrity": "sha512-yRZOat8jWGwBwHpco3uKQhVU7HYaNunZiJ4AkAVQkPCUGoZk/tiIXiwG+8HIy/F+qsiZvSOa+GLQOj3q5RKRYg==",+ "version": "5.52.1",+ "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.52.1.tgz",+ "integrity": "sha512-wkGb0hLfrS7ML3n2xIKfUIwHbjB6gxwQHyLmVHoAqEQBw+nWo+G6LoHL098FEXqahqximsntjBLuewStrnJk0g==","dev": true,"requires": {"@types/eslint-scope": "^3.7.0",@@ -8300,9 +8313,9 @@}},"ws": {- "version": "8.2.1",- "resolved": "https://registry.npmjs.org/ws/-/ws-8.2.1.tgz",- "integrity": "sha512-XkgWpJU3sHU7gX8f13NqTn6KQ85bd1WU7noBHTT8fSohx7OS1TPY8k+cyRPCzFkia7C4mM229yeHr1qK9sM4JQ=="+ "version": "8.2.2",+ "resolved": "https://registry.npmjs.org/ws/-/ws-8.2.2.tgz",+ "integrity": "sha512-Q6B6H2oc8QY3llc3cB8kVmQ6pnJWVQbP7Q5algTcIxx7YEpc0oU4NBVHlztA7Ekzfhw2r0rPducMUiCGWKQRzw=="},"xdg-basedir": {"version": "4.0.0",diff --git a/package.json b/package.jsonindex 09af2f1151..d0dabcf840 100644--- a/package.json+++ b/package.json@@ -34,7 +34,7 @@"commonmark": "0.30.0","cookie-parser": "1.4.5","csurf": "1.11.0",- "dayjs": "1.10.6",+ "dayjs": "1.10.7","ejs": "3.1.6","electron-debug": "3.2.0","electron-dl": "3.2.1",@@ -66,7 +66,7 @@"request": "^2.88.2","rimraf": "3.0.2","sanitize-filename": "1.6.3",- "sanitize-html": "2.4.0",+ "sanitize-html": "2.5.0","sax": "1.2.4","semver": "7.3.5","serve-favicon": "2.5.0",@@ -76,21 +76,21 @@"tmp": "^0.2.1","turndown": "7.1.1","unescape": "1.0.1",- "ws": "8.2.1",+ "ws": "8.2.2","yauzl": "2.10.0"},"devDependencies": {"cross-env": "7.0.3","electron": "13.3.0","electron-builder": "22.11.7",- "electron-packager": "15.3.0",+ "electron-packager": "15.4.0","electron-rebuild": "3.2.3","esm": "3.2.25","jasmine": "3.9.0","jsdoc": "3.6.7","lorem-ipsum": "2.0.3","rcedit": "3.0.1",- "webpack": "5.52.0",+ "webpack": "5.52.1","webpack-cli": "4.8.0"},"optionalDependencies": {diff --git a/src/services/consistency_checks.js b/src/services/consistency_checks.jsindex e818b8385e..d50a1cefcf 100644--- a/src/services/consistency_checks.js+++ b/src/services/consistency_checks.js@@ -282,39 +282,32 @@ class ConsistencyChecks {});this.findAndFixIssues(`- SELECT notes.noteId+ SELECT notes.noteId, notes.isProtected, notes.type, notes.mimeFROM notesLEFT JOIN note_contents USING (noteId)WHERE note_contents.noteId IS NULL`,- ({noteId}) => {+ ({noteId, isProtected, type, mime}) => {if (this.autoFix) {- const note = becca.getNote(noteId);+ const utcDateModified = dateUtils.utcNowDateTime();++ // manually creating row since this can also affect deleted notes+ sql.upsert("note_contents", "noteId", {+ noteId: noteId,+ content: getBlankContent(isProtected, type, mime),+ utcDateModified: utcDateModified,+ dateModified: dateUtils.localNowDateTime()+ });- if (note.isProtected) {- // this is wrong for non-erased notes but we cannot set a valid value for protected notes- const utcDateModified = dateUtils.utcNowDateTime();-- sql.upsert("note_contents", "noteId", {- noteId: noteId,- content: null,- utcDateModified: utcDateModified- });-- const hash = utils.hash(noteId + "|null");-- entityChangesService.addEntityChange({- entityName: 'note_contents',- entityId: noteId,- hash: hash,- isErased: false,- utcDateChanged: utcDateModified,- isSynced: true- });- }- else {- // empty string might be wrong choice for some note types but it's a best guess- note.setContent('');- }+ const hash = utils.hash(utils.randomString(10));++ entityChangesService.addEntityChange({+ entityName: 'note_contents',+ entityId: noteId,+ hash: hash,+ isErased: false,+ utcDateChanged: utcDateModified,+ isSynced: true+ });logFix(`Note ${noteId} content was set to empty string since there was no corresponding row`);} else {@@ -323,17 +316,16 @@ class ConsistencyChecks {});this.findAndFixIssues(`- SELECT noteId+ SELECT notes.noteId, notes.type, notes.mimeFROM notesJOIN note_contents USING (noteId)WHERE isDeleted = 0AND isProtected = 0AND content IS NULL`,- ({noteId}) => {+ ({noteId, type, mime}) => {if (this.autoFix) {const note = becca.getNote(noteId);- // empty string might be wrong choice for some note types but it's a best guess- note.setContent('');+ note.setContent(getBlankContent(false, type, mime));logFix(`Note ${noteId} content was set to empty string since it was null even though it is not deleted`);} else {@@ -633,6 +625,18 @@ class ConsistencyChecks {}}+function getBlankContent(isProtected, type, mime) {+ if (isProtected) {+ return null; // this is wrong for protected non-erased notes but we cannot create a valid value without password+ }++ if (mime === 'application/json') {+ return '{}';+ }++ return ''; // empty string might be wrong choice for some note types but it's a best guess+}+function logFix(message) {log.info("Consistency issue fixed: " + message);}