From 77e452671884976b3150688132ce5c6ded810c04 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 4 Mar 2021 21:42:09 +1000 Subject: [PATCH] fix notes being saved indiscriminately caused by a commit a few days ago: f61827657630ec0e6bbc5ca58c1a5ca131aede56 --- rslib/src/notes.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/rslib/src/notes.rs b/rslib/src/notes.rs index d8a316988..8467a52ab 100644 --- a/rslib/src/notes.rs +++ b/rslib/src/notes.rs @@ -323,8 +323,8 @@ impl Collection { } pub fn update_note(&mut self, note: &mut Note) -> Result<()> { - let existing_note = self.storage.get_note(note.id)?.ok_or(AnkiError::NotFound)?; - if &existing_note == note { + let mut existing_note = self.storage.get_note(note.id)?.ok_or(AnkiError::NotFound)?; + if !note_modified(&mut existing_note, note) { // nothing to do return Ok(()); } @@ -548,6 +548,18 @@ impl Collection { } } +/// The existing note pulled from the DB will have sfld and csum set, but the +/// note we receive from the frontend won't. Temporarily zero them out and +/// compare, then restore them again. +fn note_modified(existing_note: &mut Note, note: &Note) -> bool { + let sort_field = existing_note.sort_field.take(); + let checksum = existing_note.checksum.take(); + let notes_differ = existing_note != note; + existing_note.sort_field = sort_field; + existing_note.checksum = checksum; + notes_differ +} + #[derive(Debug)] pub(crate) struct NoteUpdated(Note);