fix notes being saved indiscriminately
caused by a commit a few days ago: f61827657630ec0e6bbc5ca58c1a5ca131aede56
This commit is contained in:
parent
41779c1aad
commit
77e4526718
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user