mirror of
https://github.com/ankitects/anki.git
synced 2026-01-17 15:59:03 -05:00
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.
48 lines
1.6 KiB
Rust
48 lines
1.6 KiB
Rust
// Copyright: Ankitects Pty Ltd and contributors
|
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
use super::CardQueues;
|
|
use crate::prelude::*;
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
|
pub(crate) struct MainQueueEntry {
|
|
pub id: CardId,
|
|
pub mtime: TimestampSecs,
|
|
pub kind: MainQueueEntryKind,
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
|
pub(crate) enum MainQueueEntryKind {
|
|
New,
|
|
Review,
|
|
InterdayLearning,
|
|
}
|
|
|
|
impl CardQueues {
|
|
/// Remove the head of the main queue, and update counts.
|
|
pub(super) fn pop_main(&mut self) -> Option<MainQueueEntry> {
|
|
self.main.pop_front().map(|head| {
|
|
match head.kind {
|
|
MainQueueEntryKind::New => self.counts.new -= 1,
|
|
MainQueueEntryKind::Review => self.counts.review -= 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
|
|
})
|
|
}
|
|
|
|
/// Add an undone entry to the top of the main queue.
|
|
pub(super) fn push_main(&mut self, entry: MainQueueEntry) {
|
|
match entry.kind {
|
|
MainQueueEntryKind::New => self.counts.new += 1,
|
|
MainQueueEntryKind::Review => self.counts.review += 1,
|
|
MainQueueEntryKind::InterdayLearning => self.counts.learning += 1,
|
|
};
|
|
self.main.push_front(entry);
|
|
}
|
|
}
|