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.
This commit is contained in:
Damien Elmes 2021-09-13 11:08:55 +10:00
parent 9f0929db32
commit 6fb6ffa1d7
2 changed files with 12 additions and 17 deletions

View File

@ -94,22 +94,14 @@ impl CardQueues {
mut entry: LearningQueueEntry, mut entry: LearningQueueEntry,
) -> LearningQueueEntry { ) -> LearningQueueEntry {
let cutoff = self.current_learn_ahead_cutoff(); 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 entry.due <= cutoff && self.learning_collapsed() {
if let Some(next) = self.intraday_learning.front() { if let Some(next) = self.intraday_learning.front() {
// ensure the card is scheduled after the next due card if next.due >= entry.due && next.due.adding_secs(1) < cutoff {
if next.due >= entry.due { entry.due = next.due.adding_secs(1);
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);
}
} }
} 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 .current_learning_cutoff
.adding_secs(self.learn_ahead_secs) .adding_secs(self.learn_ahead_secs)
{ {
// The saturating_sub() deals with a corner case: one remaining // Theoretically this should never go below zero.
// learning card, delayed so it doesn't appear twice. Will be
// within the current cutoff but not included in the count.
self.counts.learning = self.counts.learning.saturating_sub(1); self.counts.learning = self.counts.learning.saturating_sub(1);
} }
Some(entry) Some(entry)

View File

@ -25,7 +25,12 @@ impl CardQueues {
match head.kind { match head.kind {
MainQueueEntryKind::New => self.counts.new -= 1, MainQueueEntryKind::New => self.counts.new -= 1,
MainQueueEntryKind::Review => self.counts.review -= 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 head
}) })