From 6fb6ffa1d7c3a304e5fd4e543161bb3f9a3a5583 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 13 Sep 2021 11:08:55 +1000 Subject: [PATCH] tentative fix for learning count underflow The 'avoid showing learning card twice' logic is now only applied when the next learning card was already due to be shown. This'll mean there will be cases where a learning card does get shown twice near the end, but it makes the behaviour easier to reason about, for both us and end users. --- rslib/src/scheduler/queue/learning.rs | 22 ++++++---------------- rslib/src/scheduler/queue/main.rs | 7 ++++++- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/rslib/src/scheduler/queue/learning.rs b/rslib/src/scheduler/queue/learning.rs index 0edb61264..773c37cf2 100644 --- a/rslib/src/scheduler/queue/learning.rs +++ b/rslib/src/scheduler/queue/learning.rs @@ -94,22 +94,14 @@ impl CardQueues { mut entry: LearningQueueEntry, ) -> LearningQueueEntry { let cutoff = self.current_learn_ahead_cutoff(); + + // if the provided entry would be shown again immediately, see if we + // can place it after the next card instead if entry.due <= cutoff && self.learning_collapsed() { if let Some(next) = self.intraday_learning.front() { - // ensure the card is scheduled after the next due card - if next.due >= entry.due { - if next.due < cutoff { - entry.due = next.due.adding_secs(1) - } else { - // or outside the cutoff, in cases where the next due - // card is due later than the cutoff - entry.due = cutoff.adding_secs(60); - } + if next.due >= entry.due && next.due.adding_secs(1) < cutoff { + entry.due = next.due.adding_secs(1); } - } else { - // nothing else waiting to review; make this due a minute after - // cutoff - entry.due = cutoff.adding_secs(60); } } @@ -164,9 +156,7 @@ impl CardQueues { .current_learning_cutoff .adding_secs(self.learn_ahead_secs) { - // The saturating_sub() deals with a corner case: one remaining - // learning card, delayed so it doesn't appear twice. Will be - // within the current cutoff but not included in the count. + // Theoretically this should never go below zero. self.counts.learning = self.counts.learning.saturating_sub(1); } Some(entry) diff --git a/rslib/src/scheduler/queue/main.rs b/rslib/src/scheduler/queue/main.rs index ae48a4c36..6dc35f000 100644 --- a/rslib/src/scheduler/queue/main.rs +++ b/rslib/src/scheduler/queue/main.rs @@ -25,7 +25,12 @@ impl CardQueues { match head.kind { MainQueueEntryKind::New => self.counts.new -= 1, MainQueueEntryKind::Review => self.counts.review -= 1, - MainQueueEntryKind::InterdayLearning => self.counts.learning -= 1, + MainQueueEntryKind::InterdayLearning => { + // the bug causing learning counts to go below zero should + // hopefully be fixed at this point, but ensure we don't wrap + // if it isn't + self.counts.learning = self.counts.learning.saturating_sub(1) + } }; head })