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
added date_modified to notes_tree
azivnera5bd4c7b6a99
diff --git a/bin/www b/bin/wwwindex 03df929450..af7a8c3fad 100755--- a/bin/www+++ b/bin/www@@ -1,5 +1,9 @@#!/usr/bin/env node+process.on('unhandledRejection', (reason, p) => {+ // this makes sure that stacktrace of failed promise is printed out+ console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);+});var app = require('../app');var debug = require('debug')('node:server');diff --git a/migrations/0004__add_date_modified_to_notes_tree.sql b/migrations/0004__add_date_modified_to_notes_tree.sqlnew file mode 100644index 0000000000..c914bd1c78--- /dev/null+++ b/migrations/0004__add_date_modified_to_notes_tree.sql@@ -0,0 +1 @@+ALTER TABLE notes_tree ADD COLUMN date_modified INTEGER NOT NULL DEFAULT 0\ No newline at end of filediff --git a/routes/api/notes.js b/routes/api/notes.jsindex dcd828c095..f32ffd91c7 100644--- a/routes/api/notes.js+++ b/routes/api/notes.js@@ -153,7 +153,9 @@ router.post('/:parentNoteId/children', async (req, res, next) => {newNotePos = afterNote['note_pos'] + 1;- await sql.execute('update notes_tree set note_pos = note_pos + 1 where note_pid = ? and note_pos > ?', [parentNoteId, afterNote['note_pos']]);+ const now = utils.nowTimestamp();++ await sql.execute('update notes_tree set note_pos = note_pos + 1, date_modified = ? where note_pid = ? and note_pos > ?', [now, parentNoteId, afterNote['note_pos']]);}else {throw new ('Unknown target: ' + note['target']);@@ -179,7 +181,8 @@ router.post('/:parentNoteId/children', async (req, res, next) => {'note_id': noteId,'note_pid': parentNoteId,'note_pos': newNotePos,- 'is_expanded': 0+ 'is_expanded': 0,+ 'date_modified': utils.nowTimestamp()});await sql.commit();diff --git a/routes/api/notes_move.js b/routes/api/notes_move.jsindex bf540a12fb..6b68552b35 100644--- a/routes/api/notes_move.js+++ b/routes/api/notes_move.js@@ -20,9 +20,12 @@ router.put('/:noteId/moveTo/:parentId', auth.checkApiAuth, async (req, res, nextelsenewNotePos = maxNotePos + 1;+ const now = utils.nowTimestamp();+await sql.beginTransaction();- await sql.execute("update notes_tree set note_pid = ?, note_pos = ? where note_id = ?", [parentId, newNotePos, noteId]);+ await sql.execute("update notes_tree set note_pid = ?, note_pos = ?, date_modified = ? where note_id = ?",+ [parentId, newNotePos, now, noteId]);await sql.addAudit(audit_category.CHANGE_PARENT, req, noteId);@@ -37,12 +40,15 @@ router.put('/:noteId/moveBefore/:beforeNoteId', async (req, res, next) => {const beforeNote = await sql.getSingleResult("select * from notes_tree where note_id = ?", [beforeNoteId]);- if (beforeNote !== null) {+ if (beforeNote) {+ const now = utils.nowTimestamp();+await sql.beginTransaction();- await sql.execute("update notes_tree set note_pos = note_pos + 1 where note_id = ?", [beforeNoteId]);+ await sql.execute("update notes_tree set note_pos = note_pos + 1, date_modified = ? where note_id = ?", [now, beforeNoteId]);- await sql.execute("update notes_tree set note_pid = ?, note_pos = ? where note_id = ?", [beforeNote['note_pid'], beforeNote['note_pos'], noteId]);+ await sql.execute("update notes_tree set note_pid = ?, note_pos = ?, date_modified = ? where note_id = ?",+ [beforeNote['note_pid'], beforeNote['note_pos'], now, noteId]);await sql.addAudit(audit_category.CHANGE_POSITION, req, noteId);@@ -58,12 +64,16 @@ router.put('/:noteId/moveAfter/:afterNoteId', async (req, res, next) => {const afterNote = await sql.getSingleResult("select * from notes_tree where note_id = ?", [afterNoteId]);- if (afterNote !== null) {+ if (afterNote) {+ const now = utils.nowTimestamp();+await sql.beginTransaction();- await sql.execute("update notes_tree set note_pos = note_pos + 1 where note_pid = ? and note_pos > ?", [afterNote['note_pid'], afterNote['note_pos']]);+ await sql.execute("update notes_tree set note_pos = note_pos + 1, date_modified = ? where note_pid = ? and note_pos > ?",+ [now, afterNote['note_pid'], afterNote['note_pos']]);- await sql.execute("update notes_tree set note_pid = ?, note_pos = ? where note_id = ?", [afterNote['note_pid'], afterNote['note_pos'] + 1, noteId]);+ await sql.execute("update notes_tree set note_pid = ?, note_pos = ?, date_modified = ? where note_id = ?",+ [afterNote['note_pid'], afterNote['note_pos'] + 1, now, noteId]);await sql.addAudit(audit_category.CHANGE_POSITION, req, noteId);@@ -74,10 +84,11 @@ router.put('/:noteId/moveAfter/:afterNoteId', async (req, res, next) => {});router.put('/:noteId/expanded/:expanded', async (req, res, next) => {- let noteId = req.params.noteId;- let expanded = req.params.expanded;+ const noteId = req.params.noteId;+ const expanded = req.params.expanded;+ const now = utils.nowTimestamp();- await sql.execute("update notes_tree set is_expanded = ? where note_id = ?", [expanded, noteId]);+ await sql.execute("update notes_tree set is_expanded = ?, date_modified = ? where note_id = ?", [expanded, now, noteId]);// no audit here, not really importantdiff --git a/services/migration.js b/services/migration.jsindex 986d5313a1..70c8a9f648 100644--- a/services/migration.js+++ b/services/migration.js@@ -2,7 +2,7 @@ const backup = require('./backup');const sql = require('./sql');const fs = require('fs-extra');-const APP_DB_VERSION = 3;+const APP_DB_VERSION = 4;const MIGRATIONS_DIR = "./migrations";async function migrate() {