Skip update when note left unchanged

This commit is contained in:
Adrian Gruntkowski 2025-02-08 01:20:08 +01:00
parent fb80d4e1f9
commit 799d6b16b0
2 changed files with 21 additions and 1 deletions

View file

@ -225,7 +225,7 @@ function renderNote(note) {
container.addEventListener("click", async (e) => { container.addEventListener("click", async (e) => {
const note = await Notes.get(container.id); const note = await Notes.get(container.id);
editNote.load(note); editNote.load(structuredClone(note));
editNoteDialog.showModal(); editNoteDialog.showModal();
}); });

View file

@ -1,6 +1,20 @@
let databases = {}; let databases = {};
let memory = {}; let memory = {};
function notesEqual(n1, n2) {
return (
n1.id === n2.id &&
n1.type === n2.type &&
n1.content === n2.content &&
n1.deleted === n2.deleted &&
n1.reminder?.enabled === n2.reminder?.enabled &&
n1.reminder?.date === n2.reminder?.date &&
n1.reminder?.time === n2.reminder?.time &&
n1.reminder?.repeat === n2.reminder?.repeat &&
n1.reminder?.unit === n2.reminder?.unit
);
}
async function connect(dbName) { async function connect(dbName) {
if (!databases[dbName]) { if (!databases[dbName]) {
databases[dbName] = await dbConnect(dbName); databases[dbName] = await dbConnect(dbName);
@ -216,6 +230,12 @@ export class SyncedNoteStore extends EventTarget {
async update(note, skipNetwork) { async update(note, skipNetwork) {
const that = this; const that = this;
const existingNote = memory[this.dbName][this.storeName][note.id];
if (existingNote && notesEqual(note, existingNote)) {
return existingNote;
}
if (!skipNetwork) { if (!skipNetwork) {
note.updated = Date.now(); note.updated = Date.now();
} }