diff --git a/rslib/src/scheduler/fsrs/retention.rs b/rslib/src/scheduler/fsrs/retention.rs index 359821a52..d4c8f05ee 100644 --- a/rslib/src/scheduler/fsrs/retention.rs +++ b/rslib/src/scheduler/fsrs/retention.rs @@ -73,7 +73,7 @@ impl Collection { .search_cards_into_table(search, SortMode::NoOrder)? .col .storage - .get_revlog_entries_for_searched_cards_in_order()?; + .get_revlog_entries_for_searched_cards_in_card_order()?; let first_rating_count = revlogs .iter() diff --git a/rslib/src/scheduler/fsrs/weights.rs b/rslib/src/scheduler/fsrs/weights.rs index 5dece4863..c5d5f27fe 100644 --- a/rslib/src/scheduler/fsrs/weights.rs +++ b/rslib/src/scheduler/fsrs/weights.rs @@ -15,6 +15,8 @@ use itertools::Itertools; use crate::prelude::*; use crate::revlog::RevlogEntry; use crate::revlog::RevlogReviewKind; +use crate::search::Node; +use crate::search::SearchNode; use crate::search::SortMode; pub(crate) type Weights = Vec; @@ -57,10 +59,17 @@ impl Collection { &mut self, search: impl TryIntoSearch, ) -> Result> { + let search = search.try_into_search()?; + // a whole-collection search can match revlog entries of deleted cards, too + if let Node::Group(nodes) = &search { + if let &[Node::Search(SearchNode::WholeCollection)] = &nodes[..] { + return self.storage.get_all_revlog_entries_in_card_order(); + } + } self.search_cards_into_table(search, SortMode::NoOrder)? .col .storage - .get_revlog_entries_for_searched_cards_in_order() + .get_revlog_entries_for_searched_cards_in_card_order() } pub fn evaluate_weights(&mut self, weights: &Weights, search: &str) -> Result { @@ -70,7 +79,7 @@ impl Collection { let revlogs = guard .col .storage - .get_revlog_entries_for_searched_cards_in_order()?; + .get_revlog_entries_for_searched_cards_in_card_order()?; anki_progress.state.fsrs_items = revlogs.len() as u32; let items = fsrs_items_for_training(revlogs, timing.next_day_at); let fsrs = FSRS::new(Some(weights))?; diff --git a/rslib/src/storage/revlog/mod.rs b/rslib/src/storage/revlog/mod.rs index 3de6fa768..03b72b8b1 100644 --- a/rslib/src/storage/revlog/mod.rs +++ b/rslib/src/storage/revlog/mod.rs @@ -142,7 +142,7 @@ impl SqliteStorage { .collect() } - pub(crate) fn get_revlog_entries_for_searched_cards_in_order( + pub(crate) fn get_revlog_entries_for_searched_cards_in_card_order( &self, ) -> Result> { self.db @@ -154,6 +154,13 @@ impl SqliteStorage { .collect() } + pub(crate) fn get_all_revlog_entries_in_card_order(&self) -> Result> { + self.db + .prepare_cached(concat!(include_str!("get.sql"), " order by cid, id"))? + .query_and_then([], row_to_revlog_entry)? + .collect() + } + pub(crate) fn get_all_revlog_entries(&self, after: TimestampSecs) -> Result> { self.db .prepare_cached(concat!(include_str!("get.sql"), " where id >= ?"))?