mirror of
https://github.com/ankitects/anki.git
synced 2025-09-25 01:06:35 -04:00
better leech tag handling for test scheduler
This commit is contained in:
parent
ea319b3dfc
commit
6775002709
3 changed files with 3 additions and 30 deletions
|
@ -559,33 +559,6 @@ impl Collection {
|
||||||
Ok(DuplicateState::Empty)
|
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<F>(&mut self, nid: NoteId, mutator: F) -> Result<()>
|
|
||||||
where
|
|
||||||
F: Fn(&mut Vec<String>),
|
|
||||||
{
|
|
||||||
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
|
/// The existing note pulled from the DB will have sfld and csum set, but the
|
||||||
|
|
|
@ -267,7 +267,6 @@ impl Collection {
|
||||||
let timing = updater.timing;
|
let timing = updater.timing;
|
||||||
let mut card = updater.into_card();
|
let mut card = updater.into_card();
|
||||||
self.update_card_inner(&mut card, original, usn)?;
|
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() {
|
if answer.new_state.leeched() {
|
||||||
self.add_leech_tag(card.note_id)?;
|
self.add_leech_tag(card.note_id)?;
|
||||||
}
|
}
|
||||||
|
@ -371,7 +370,8 @@ impl Collection {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_leech_tag(&mut self, nid: NoteId) -> Result<()> {
|
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(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ impl Collection {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Collection {
|
impl Collection {
|
||||||
fn add_tags_to_notes_inner(&mut self, nids: &[NoteId], tags: &str) -> Result<usize> {
|
pub(crate) fn add_tags_to_notes_inner(&mut self, nids: &[NoteId], tags: &str) -> Result<usize> {
|
||||||
let usn = self.usn()?;
|
let usn = self.usn()?;
|
||||||
|
|
||||||
// will update tag list for any new tags, and match case
|
// will update tag list for any new tags, and match case
|
||||||
|
|
Loading…
Reference in a new issue