Skip to content

Build your personal knowledge base with Trilium Notes

sync debugging tweaks etc.

azivner1c501beea9da
diff --git a/services/event_log.js b/services/event_log.js
index 2e1ce39713..881b352af3 100644
--- a/services/event_log.js
+++ b/services/event_log.js
@@ -1,5 +1,6 @@
const sql = require('./sql');
const utils = require('./utils');
+const log = require('./log');
async function addEvent(comment) {
await addNoteEvent(null, comment);
@@ -11,6 +12,8 @@ async function addNoteEvent(noteId, comment) {
comment: comment,
date_added: utils.nowTimestamp()
});
+
+ log.info("Event log for " + noteId + ": " + comment);
}
module.exports = {
diff --git a/services/notes.js b/services/notes.js
index b62fe86512..3ff5902dc2 100644
--- a/services/notes.js
+++ b/services/notes.js
@@ -37,8 +37,8 @@ async function createNewNote(parentNoteId, note, browserId) {
await sql.doInTransaction(async () => {
await sql.addAudit(audit_category.CREATE_NOTE, browserId, noteId);
- await sql.addNoteTreeSync(noteId, browserId);
- await sql.addNoteSync(noteId, browserId);
+ await sql.addNoteTreeSync(noteId);
+ await sql.addNoteSync(noteId);
const now = utils.nowTimestamp();
@@ -167,8 +167,8 @@ async function deleteNote(noteId, browserId) {
await sql.execute("update notes_tree set is_deleted = 1, date_modified = ? where note_id = ?", [now, noteId]);
await sql.execute("update notes set is_deleted = 1, date_modified = ? where note_id = ?", [now, noteId]);
- await sql.addNoteTreeSync(noteId, browserId);
- await sql.addNoteSync(noteId, browserId);
+ await sql.addNoteTreeSync(noteId);
+ await sql.addNoteSync(noteId);
await sql.addAudit(audit_category.DELETE_NOTE, browserId, noteId);
}
diff --git a/services/sync.js b/services/sync.js
index 1068c9b93f..ab5b631205 100644
--- a/services/sync.js
+++ b/services/sync.js
@@ -304,7 +304,7 @@ async function updateNote(entity, links, sourceId) {
logSync("Update/sync note " + entity.note_id);
}
else {
- await eventLog.addNoteEvent(entity.note_id, "Sync conflict in note <note>");
+ await eventLog.addNoteEvent(entity.note_id, "Sync conflict in note <note>, " + utils.formatTwoTimestamps(origNote.date_modified, entity.date_modified));
}
}
@@ -323,7 +323,7 @@ async function updateNoteTree(entity, sourceId) {
logSync("Update/sync note tree " + entity.note_id);
}
else {
- await eventLog.addNoteEvent(entity.note_id, "Sync conflict in note tree <note>");
+ await eventLog.addNoteEvent(entity.note_id, "Sync conflict in note tree <note>, " + utils.formatTwoTimestamps(orig.date_modified, entity.date_modified));
}
}
@@ -340,7 +340,7 @@ async function updateNoteHistory(entity, sourceId) {
logSync("Update/sync note history " + entity.note_history_id);
}
else {
- await eventLog.addNoteEvent(entity.note_id, "Sync conflict in note history for <note>");
+ await eventLog.addNoteEvent(entity.note_id, "Sync conflict in note history for <note>, " + utils.formatTwoTimestamps(orig.date_modified_to, entity.date_modified_to));
}
}
@@ -372,7 +372,7 @@ async function updateOptions(entity, sourceId) {
await eventLog.addEvent("Synced option " + entity.opt_name);
}
else {
- await eventLog.addEvent("Sync conflict in options for " + entity.opt_name);
+ await eventLog.addEvent("Sync conflict in options for " + entity.opt_name + ", " + utils.formatTwoTimestamps(orig.date_modified, entity.date_modified));
}
}
diff --git a/services/utils.js b/services/utils.js
index 367897fbf0..a19f73047f 100644
--- a/services/utils.js
+++ b/services/utils.js
@@ -48,6 +48,16 @@ function isElectron() {
return !!process.versions['electron'];
}
+function formatDateTimeFromTS(timestamp) {
+ const date = new Date(timestamp * 1000);
+
+ return date.toISOString();
+}
+
+function formatTwoTimestamps(origTS, newTS) {
+ return "orig: " + formatDateTimeFromTS(origTS) + ", new: " + formatDateTimeFromTS(newTS);
+}
+
module.exports = {
randomSecureToken,
randomString,
@@ -57,5 +67,6 @@ module.exports = {
fromBase64,
hmac,
browserId,
- isElectron
+ isElectron,
+ formatTwoTimestamps
};
\ No newline at end of file