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:
parent
9f0929db32
commit
6fb6ffa1d7
@ -94,23 +94,15 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
self.insert_intraday_learning_card(entry);
|
||||
@ -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)
|
||||
|
@ -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
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user