modify generate_cards_for_note to return count

This commit is contained in:
llama 2025-09-01 22:11:57 +08:00
parent 8ef208e418
commit 95d7445ff6
No known key found for this signature in database
GPG key ID: 0B7543854B9413C3

View file

@ -215,7 +215,7 @@ impl Collection {
ctx: &CardGenContext<impl Deref<Target = Notetype>>, ctx: &CardGenContext<impl Deref<Target = Notetype>>,
note: &Note, note: &Note,
target_deck_id: DeckId, target_deck_id: DeckId,
) -> Result<()> { ) -> Result<usize> {
self.generate_cards_for_note( self.generate_cards_for_note(
ctx, ctx,
note, note,
@ -231,7 +231,8 @@ impl Collection {
note: &Note, note: &Note,
) -> Result<()> { ) -> Result<()> {
let existing = self.storage.existing_cards_for_note(note.id)?; let existing = self.storage.existing_cards_for_note(note.id)?;
self.generate_cards_for_note(ctx, note, &existing, ctx.last_deck, &mut Default::default()) self.generate_cards_for_note(ctx, note, &existing, ctx.last_deck, &mut Default::default())?;
Ok(())
} }
fn generate_cards_for_note( fn generate_cards_for_note(
@ -241,12 +242,13 @@ impl Collection {
existing: &[AlreadyGeneratedCardInfo], existing: &[AlreadyGeneratedCardInfo],
target_deck_id: Option<DeckId>, target_deck_id: Option<DeckId>,
cache: &mut CardGenCache, cache: &mut CardGenCache,
) -> Result<()> { ) -> Result<usize> {
let cards = ctx.new_cards_required(note, existing, true); let cards = ctx.new_cards_required(note, existing, true);
if cards.is_empty() { if cards.is_empty() {
return Ok(()); return Ok(0);
} }
self.add_generated_cards(note.id, &cards, target_deck_id, cache) self.add_generated_cards(note.id, &cards, target_deck_id, cache)?;
Ok(cards.len())
} }
pub(crate) fn generate_cards_for_notetype( pub(crate) fn generate_cards_for_notetype(