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
don't sync recent_notes
zadam9f19cf80463b
diff --git a/db/migrations/0182__remove_recentChanges_from_entityChanges.sql b/db/migrations/0182__remove_recentChanges_from_entityChanges.sqlnew file mode 100644index 0000000000..c09b6191a3--- /dev/null+++ b/db/migrations/0182__remove_recentChanges_from_entityChanges.sql@@ -0,0 +1,14 @@+DELETE FROM entity_changes WHERE entityName = 'recent_notes';++CREATE TABLE IF NOT EXISTS "mig_recent_notes"+(+ noteId TEXT not null primary key,+ notePath TEXT not null,+ utcDateCreated TEXT not null+);++INSERT INTO mig_recent_notes (noteId, notePath, utcDateCreated)+ SELECT noteId, notePath, utcDateCreated FROM recent_notes;++DROP TABLE recent_notes;+ALTER TABLE mig_recent_notes RENAME TO recent_notes;diff --git a/src/entities/entity.js b/src/entities/entity.jsindex 37a0efb538..1bb6525831 100644--- a/src/entities/entity.js+++ b/src/entities/entity.js@@ -15,7 +15,7 @@ class Entity {}}- if ('isDeleted' in this) {+ if ('isDeleted' in this && this.constructor.entityName !== 'recent_notes') {this.isDeleted = !!this.isDeleted;}}diff --git a/src/entities/recent_note.js b/src/entities/recent_note.jsindex 45012a7317..f4ef899e61 100644--- a/src/entities/recent_note.js+++ b/src/entities/recent_note.js@@ -8,21 +8,15 @@ const dateUtils = require('../services/date_utils');** @property {string} noteId* @property {string} notePath- * @property {boolean} isDeleted- * @property {string} utcDateModified+ * @property {string} utcDateCreated** @extends Entity*/class RecentNote extends Entity {static get entityName() { return "recent_notes"; }static get primaryKeyName() { return "noteId"; }- static get hashedProperties() { return ["noteId", "notePath", "utcDateCreated", "isDeleted"]; }beforeSaving() {- if (!this.isDeleted) {- this.isDeleted = false;- }-if (!this.utcDateCreated) {this.utcDateCreated = dateUtils.utcNowDateTime();}@@ -31,4 +25,4 @@ class RecentNote extends Entity {}}-module.exports = RecentNote;\ No newline at end of file+module.exports = RecentNote;diff --git a/src/routes/api/recent_notes.js b/src/routes/api/recent_notes.jsindex 678c1de431..2b6594f4d6 100644--- a/src/routes/api/recent_notes.js+++ b/src/routes/api/recent_notes.js@@ -1,12 +1,21 @@"use strict";const RecentNote = require('../../entities/recent_note');+const sql = require('../../services/sql');+const dateUtils = require('../../services/date_utils');function addRecentNote(req) {new RecentNote({noteId: req.body.noteId,notePath: req.body.notePath}).save();++ if (Math.random() < 0.05) {+ // it's not necessary to run this everytime ...+ const cutOffDate = dateUtils.utcDateStr(new Date(Date.now() - 24 * 3600 * 1000));++ sql.execute(`DELETE FROM recent_notes WHERE utcDateCreated < ?`, [cutOffDate]);+ }}module.exports = {diff --git a/src/services/app_info.js b/src/services/app_info.jsindex 0705701656..b3fcd9a734 100644--- a/src/services/app_info.js+++ b/src/services/app_info.js@@ -4,8 +4,8 @@ const build = require('./build');const packageJson = require('../../package');const {TRILIUM_DATA_DIR} = require('./data_dir');-const APP_DB_VERSION = 181;-const SYNC_VERSION = 19;+const APP_DB_VERSION = 182;+const SYNC_VERSION = 20;const CLIPPER_PROTOCOL_VERSION = "1.0";module.exports = {diff --git a/src/services/consistency_checks.js b/src/services/consistency_checks.jsindex 014772a126..f225f90a5b 100644--- a/src/services/consistency_checks.js+++ b/src/services/consistency_checks.js@@ -505,7 +505,6 @@ class ConsistencyChecks {this.runEntityChangeChecks("note_contents", "noteId");this.runEntityChangeChecks("note_revisions", "noteRevisionId");this.runEntityChangeChecks("branches", "branchId");- this.runEntityChangeChecks("recent_notes", "noteId");this.runEntityChangeChecks("attributes", "attributeId");this.runEntityChangeChecks("api_tokens", "apiTokenId");this.runEntityChangeChecks("options", "name");diff --git a/src/services/note_cache/similarity.js b/src/services/note_cache/similarity.jsindex ddca8c3069..116f512674 100644--- a/src/services/note_cache/similarity.js+++ b/src/services/note_cache/similarity.js@@ -1,4 +1,5 @@const noteCache = require('./note_cache');+const log = require('../log');const noteCacheService = require('./note_cache_service.js');const dateUtils = require('../date_utils');const repository = require('../repository');@@ -333,7 +334,7 @@ async function findSimilarNotes(noteId) {let value = attr.value;let factor = 1;- if (!value) {+ if (!value.startsWith) {log.info(`Unexpected falsy value for attribute ${JSON.stringify(attr.pojo)}`);continue;}diff --git a/src/services/repository.js b/src/services/repository.jsindex 898b5721f6..9d8190876b 100644--- a/src/services/repository.js+++ b/src/services/repository.js@@ -111,6 +111,10 @@ function updateEntity(entity) {sql.transactional(() => {sql.upsert(entityName, primaryKeyName, clone);+ if (entityName === 'recent_notes') {+ return;+ }+const entityId = entity[primaryKeyName];const isSynced = entityName !== 'options' || entity.isSynced;