mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 08:46:37 -04:00
Add deck-specific limits to DeckNormal
This commit is contained in:
parent
9dcceff4af
commit
e907ca220c
3 changed files with 33 additions and 15 deletions
|
@ -69,8 +69,10 @@ message Deck {
|
|||
uint32 extend_review = 3;
|
||||
string description = 4;
|
||||
bool markdown_description = 5;
|
||||
optional uint32 review_limit = 6;
|
||||
optional uint32 new_limit = 7;
|
||||
|
||||
reserved 6 to 11;
|
||||
reserved 8 to 11;
|
||||
}
|
||||
message Filtered {
|
||||
message SearchTerm {
|
||||
|
|
|
@ -5,7 +5,7 @@ use std::{collections::HashMap, iter::Peekable};
|
|||
|
||||
use id_tree::{InsertBehavior, Node, NodeId, Tree};
|
||||
|
||||
use super::Deck;
|
||||
use super::{Deck, NormalDeck};
|
||||
use crate::{
|
||||
deckconfig::{DeckConfig, DeckConfigId},
|
||||
prelude::*,
|
||||
|
@ -19,19 +19,33 @@ pub(crate) struct RemainingLimits {
|
|||
|
||||
impl RemainingLimits {
|
||||
pub(crate) fn new(deck: &Deck, config: Option<&DeckConfig>, today: u32, v3: bool) -> Self {
|
||||
config
|
||||
.map(|config| {
|
||||
let (new_today, mut rev_today) = deck.new_rev_counts(today);
|
||||
if v3 {
|
||||
// any reviewed new cards contribute to the review limit
|
||||
rev_today += new_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()
|
||||
if let Ok(normal) = deck.normal() {
|
||||
if let Some(config) = config {
|
||||
return Self::new_for_normal_deck(deck, today, v3, normal, config);
|
||||
}
|
||||
}
|
||||
Self::default()
|
||||
}
|
||||
|
||||
fn new_for_normal_deck(
|
||||
deck: &Deck,
|
||||
today: u32,
|
||||
v3: bool,
|
||||
normal: &NormalDeck,
|
||||
config: &DeckConfig,
|
||||
) -> RemainingLimits {
|
||||
let review_limit = normal.review_limit.unwrap_or(config.inner.reviews_per_day);
|
||||
let new_limit = normal.new_limit.unwrap_or(config.inner.new_per_day);
|
||||
let (new_today, mut rev_today) = deck.new_rev_counts(today);
|
||||
if v3 {
|
||||
// any reviewed new cards contribute to the review limit
|
||||
rev_today += new_today;
|
||||
}
|
||||
|
||||
Self {
|
||||
review: (review_limit as i32 - rev_today).max(0) as u32,
|
||||
new: (new_limit as i32 - new_today).max(0) as u32,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn cap_to(&mut self, limits: RemainingLimits) {
|
||||
|
|
|
@ -298,6 +298,8 @@ impl From<NormalDeckSchema11> for NormalDeck {
|
|||
extend_review: deck.extend_rev.max(0) as u32,
|
||||
markdown_description: deck.common.markdown_description,
|
||||
description: deck.common.desc,
|
||||
review_limit: None,
|
||||
new_limit: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue