From d2337e4cd36c72337b20336eebf2a45ca7ecde36 Mon Sep 17 00:00:00 2001 From: RumovZ Date: Thu, 15 Apr 2021 19:53:11 +0200 Subject: [PATCH] Move some methods into decks/counts.rs --- rslib/src/decks/counts.rs | 30 ++++++++++++++++++++++++++++-- rslib/src/decks/mod.rs | 23 ----------------------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/rslib/src/decks/counts.rs b/rslib/src/decks/counts.rs index 26f547864..436107b34 100644 --- a/rslib/src/decks/counts.rs +++ b/rslib/src/decks/counts.rs @@ -1,7 +1,8 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html - -use crate::{collection::Collection, decks::DeckId, error::Result}; +use crate::{ + backend_proto as pb, collection::Collection, decks::DeckId, error::Result, prelude::*, +}; use std::collections::HashMap; #[derive(Debug)] @@ -11,6 +12,18 @@ pub(crate) struct DueCounts { pub learning: u32, } +impl Deck { + /// Return the studied counts if studied today. + /// May be negative if user has extended limits. + pub(crate) fn new_rev_counts(&self, today: u32) -> (i32, i32) { + if self.common.last_day_studied == today { + (self.common.new_studied, self.common.review_studied) + } else { + (0, 0) + } + } +} + impl Collection { /// Get due counts for decks at the given timestamp. pub(crate) fn due_counts( @@ -26,4 +39,17 @@ impl Collection { limit_to, ) } + + pub(crate) fn counts_for_deck_today( + &mut self, + did: DeckId, + ) -> Result { + let today = self.current_due_day(0)?; + let mut deck = self.storage.get_deck(did)?.ok_or(AnkiError::NotFound)?; + deck.reset_stats_if_day_changed(today); + Ok(pb::CountsForDeckTodayOut { + new: deck.common.new_studied, + review: deck.common.review_studied, + }) + } } diff --git a/rslib/src/decks/mod.rs b/rslib/src/decks/mod.rs index c90ac488f..3330cb83b 100644 --- a/rslib/src/decks/mod.rs +++ b/rslib/src/decks/mod.rs @@ -125,16 +125,6 @@ impl Deck { self.usn = usn; } - /// Return the studied counts if studied today. - /// May be negative if user has extended limits. - pub(crate) fn new_rev_counts(&self, today: u32) -> (i32, i32) { - if self.common.last_day_studied == today { - (self.common.new_studied, self.common.review_studied) - } else { - (0, 0) - } - } - pub fn rendered_description(&self) -> String { if let DeckKind::Normal(normal) = &self.kind { if normal.markdown_description { @@ -239,19 +229,6 @@ impl Collection { Ok(()) } - pub(crate) fn counts_for_deck_today( - &mut self, - did: DeckId, - ) -> Result { - let today = self.current_due_day(0)?; - let mut deck = self.storage.get_deck(did)?.ok_or(AnkiError::NotFound)?; - deck.reset_stats_if_day_changed(today); - Ok(pb::CountsForDeckTodayOut { - new: deck.common.new_studied, - review: deck.common.review_studied, - }) - } - fn update_deck_stats_single( &mut self, today: u32,