mirror of
https://github.com/ankitects/anki.git
synced 2025-12-10 21:36:55 -05:00
fix notes being saved indiscriminately
caused by a commit a few days ago: f61827657630ec0e6bbc5ca58c1a5ca131aede56
This commit is contained in:
parent
41779c1aad
commit
77e4526718
1 changed files with 14 additions and 2 deletions
|
|
@ -323,8 +323,8 @@ impl Collection {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_note(&mut self, note: &mut Note) -> Result<()> {
|
pub fn update_note(&mut self, note: &mut Note) -> Result<()> {
|
||||||
let existing_note = self.storage.get_note(note.id)?.ok_or(AnkiError::NotFound)?;
|
let mut existing_note = self.storage.get_note(note.id)?.ok_or(AnkiError::NotFound)?;
|
||||||
if &existing_note == note {
|
if !note_modified(&mut existing_note, note) {
|
||||||
// nothing to do
|
// nothing to do
|
||||||
return Ok(());
|
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)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct NoteUpdated(Note);
|
pub(crate) struct NoteUpdated(Note);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue