update learning cutoff when counts are zero

This commit is contained in:
Damien Elmes 2021-08-02 15:02:03 +10:00
parent 94c7c3282b
commit 3cec1a35dc
2 changed files with 19 additions and 5 deletions

View File

@ -35,7 +35,7 @@ impl CardQueues {
/// Increase the cutoff to the current time, and increase the learning count /// Increase the cutoff to the current time, and increase the learning count
/// for any new cards that now fall within the cutoff. /// for any new cards that now fall within the cutoff.
pub(super) fn check_for_newly_due_intraday_learning(&mut self) -> Box<CutoffSnapshot> { pub(super) fn update_learning_cutoff_and_count(&mut self) -> Box<CutoffSnapshot> {
let change = CutoffSnapshot { let change = CutoffSnapshot {
learning_count: self.counts.learning, learning_count: self.counts.learning,
learning_cutoff: self.current_learning_cutoff, learning_cutoff: self.current_learning_cutoff,

View File

@ -26,8 +26,9 @@ pub(crate) struct CardQueues {
selected_deck: DeckId, selected_deck: DeckId,
current_day: u32, current_day: u32,
learn_ahead_secs: i64, learn_ahead_secs: i64,
/// Updated each time a card is answered. Ensures we don't show a newly-due /// Updated each time a card is answered, and by get_queued_cards() when the
/// learning card after a user returns from editing a review card. /// counts are zero. Ensures we don't show a newly-due learning card after a
/// user returns from editing a review card.
current_learning_cutoff: TimestampSecs, current_learning_cutoff: TimestampSecs,
} }
@ -38,6 +39,12 @@ pub struct Counts {
pub review: usize, pub review: usize,
} }
impl Counts {
fn all_zero(self) -> bool {
self.new == 0 && self.learning == 0 && self.review == 0
}
}
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct QueuedCard { pub struct QueuedCard {
pub card: Card, pub card: Card,
@ -148,7 +155,14 @@ impl CardQueues {
} }
} }
pub(crate) fn counts(&self) -> Counts { /// Return the current due counts. If there are no due cards, the learning
/// cutoff is updated to the current time first, and any newly-due learning
/// cards are added to the counts.
pub(crate) fn counts(&mut self) -> Counts {
if self.counts.all_zero() {
// we discard the returned undo information in this case
self.update_learning_cutoff_and_count();
}
self.counts self.counts
} }
@ -179,7 +193,7 @@ impl Collection {
if let Some(queues) = &mut self.state.card_queues { if let Some(queues) = &mut self.state.card_queues {
let entry = queues.pop_entry(card.id)?; let entry = queues.pop_entry(card.id)?;
let requeued_learning = queues.maybe_requeue_learning_card(card, timing); let requeued_learning = queues.maybe_requeue_learning_card(card, timing);
let cutoff_change = queues.check_for_newly_due_intraday_learning(); let cutoff_change = queues.update_learning_cutoff_and_count();
self.save_queue_update_undo(Box::new(QueueUpdate { self.save_queue_update_undo(Box::new(QueueUpdate {
entry, entry,
learning_requeue: requeued_learning, learning_requeue: requeued_learning,