mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 07:22:23 -04:00

- Daily limits are no longer inherited - each deck limits its own cards, and the selected deck enforces a maximum limit. - Fetching of review cards now uses a single query, and sorts in advance. In collections with a large number of overdue cards and decks, this is faster than iterating over each deck in turn. - Include interday learning count in review count & review limit, and allow them to be buried. - Warn when parent review limit is lower than child deck in deck options. - Cap the new card limit to the review limit. - Add option to control whether new card fetching short-circuits.
59 lines
1.6 KiB
Rust
59 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 std::collections::HashMap;
|
|
|
|
use super::Deck;
|
|
use crate::{
|
|
deckconfig::{DeckConfig, DeckConfigId},
|
|
prelude::*,
|
|
};
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
|
pub(crate) struct RemainingLimits {
|
|
pub review: u32,
|
|
pub new: u32,
|
|
}
|
|
|
|
impl RemainingLimits {
|
|
pub(crate) fn new(deck: &Deck, config: Option<&DeckConfig>, today: u32) -> Self {
|
|
config
|
|
.map(|config| {
|
|
let (new_today, rev_today) = deck.new_rev_counts(today);
|
|
RemainingLimits {
|
|
review: ((config.inner.reviews_per_day as i32) - rev_today).max(0) as u32,
|
|
new: ((config.inner.new_per_day as i32) - new_today).max(0) as u32,
|
|
}
|
|
})
|
|
.unwrap_or_default()
|
|
}
|
|
|
|
pub(crate) fn cap_to(&mut self, limits: RemainingLimits) {
|
|
self.review = self.review.min(limits.review);
|
|
self.new = self.new.min(limits.new);
|
|
}
|
|
}
|
|
|
|
impl Default for RemainingLimits {
|
|
fn default() -> Self {
|
|
RemainingLimits {
|
|
review: 9999,
|
|
new: 9999,
|
|
}
|
|
}
|
|
}
|
|
|
|
pub(crate) fn remaining_limits_map<'a>(
|
|
decks: impl Iterator<Item = &'a Deck>,
|
|
config: &'a HashMap<DeckConfigId, DeckConfig>,
|
|
today: u32,
|
|
) -> HashMap<DeckId, RemainingLimits> {
|
|
decks
|
|
.map(|deck| {
|
|
(
|
|
deck.id,
|
|
RemainingLimits::new(deck, deck.config_id().and_then(|id| config.get(&id)), today),
|
|
)
|
|
})
|
|
.collect()
|
|
}
|