From 67750027097221f9194e51b2f540b2d76c020b21 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 10 May 2021 14:58:04 +1000 Subject: [PATCH] better leech tag handling for test scheduler --- rslib/src/notes/mod.rs | 27 --------------------------- rslib/src/scheduler/answering/mod.rs | 4 ++-- rslib/src/tags/bulkadd.rs | 2 +- 3 files changed, 3 insertions(+), 30 deletions(-) diff --git a/rslib/src/notes/mod.rs b/rslib/src/notes/mod.rs index 5b3fc0a10..56c09c53d 100644 --- a/rslib/src/notes/mod.rs +++ b/rslib/src/notes/mod.rs @@ -559,33 +559,6 @@ impl Collection { Ok(DuplicateState::Empty) } } - - /// Update the tags of the provided note, canonifying before save. Requires a transaction. - /// Fixme: this currently pulls in the note type, and does more work than necessary. We - /// could add a separate method to the storage layer to just update the tags in the future, - /// though it does slightly complicate the undo story. - pub(crate) fn update_note_tags(&mut self, nid: NoteId, mutator: F) -> Result<()> - where - F: Fn(&mut Vec), - { - self.transform_notes(&[nid], |note, _nt| { - let mut tags = note.tags.clone(); - mutator(&mut tags); - let changed = if tags != note.tags { - note.tags = tags; - true - } else { - false - }; - Ok(TransformNoteOutput { - changed, - generate_cards: false, - mark_modified: true, - update_tags: true, - }) - }) - .map(|_| ()) - } } /// The existing note pulled from the DB will have sfld and csum set, but the diff --git a/rslib/src/scheduler/answering/mod.rs b/rslib/src/scheduler/answering/mod.rs index 56a1ac075..9e319ee03 100644 --- a/rslib/src/scheduler/answering/mod.rs +++ b/rslib/src/scheduler/answering/mod.rs @@ -267,7 +267,6 @@ impl Collection { let timing = updater.timing; let mut card = updater.into_card(); self.update_card_inner(&mut card, original, usn)?; - println!("fixme: add_leech calls update_note_tags() which creates a transaction"); if answer.new_state.leeched() { self.add_leech_tag(card.note_id)?; } @@ -371,7 +370,8 @@ impl Collection { } fn add_leech_tag(&mut self, nid: NoteId) -> Result<()> { - self.update_note_tags(nid, |tags| tags.push("leech".into())) + self.add_tags_to_notes_inner(&[nid], "leech")?; + Ok(()) } } diff --git a/rslib/src/tags/bulkadd.rs b/rslib/src/tags/bulkadd.rs index 320a18ca8..33dabf126 100644 --- a/rslib/src/tags/bulkadd.rs +++ b/rslib/src/tags/bulkadd.rs @@ -17,7 +17,7 @@ impl Collection { } impl Collection { - fn add_tags_to_notes_inner(&mut self, nids: &[NoteId], tags: &str) -> Result { + pub(crate) fn add_tags_to_notes_inner(&mut self, nids: &[NoteId], tags: &str) -> Result { let usn = self.usn()?; // will update tag list for any new tags, and match case