From c39f2cacae555ee1b68b1f07a50c6ce403358511 Mon Sep 17 00:00:00 2001 From: RumovZ Date: Sun, 24 Dec 2023 11:04:28 +0100 Subject: [PATCH] Fix new cards from parent decks being gathered (#2907) Fixes #2906. --- rslib/src/decks/limits.rs | 10 ---------- rslib/src/scheduler/queue/builder/gathering.rs | 2 +- rslib/src/storage/deck/active_deck_ids_sorted.sql | 7 +++++++ rslib/src/storage/deck/mod.rs | 7 +++++++ 4 files changed, 15 insertions(+), 11 deletions(-) create mode 100644 rslib/src/storage/deck/active_deck_ids_sorted.sql diff --git a/rslib/src/decks/limits.rs b/rslib/src/decks/limits.rs index 77a59354a..0866a214c 100644 --- a/rslib/src/decks/limits.rs +++ b/rslib/src/decks/limits.rs @@ -190,7 +190,6 @@ pub(crate) fn remaining_limits_map<'a>( /// Wrapper of [RemainingLimits] with some additional meta data. #[derive(Debug, Clone, Copy)] struct NodeLimits { - deck_id: DeckId, /// absolute level in the deck hierarchy level: usize, limits: RemainingLimits, @@ -204,7 +203,6 @@ impl NodeLimits { new_cards_ignore_review_limit: bool, ) -> Self { Self { - deck_id: deck.id, level: deck.name.components().count(), limits: RemainingLimits::new( deck, @@ -365,14 +363,6 @@ impl LimitTreeMap { Ok(self.get_deck_limits(deck_id)?.get(kind) == 0) } - pub(crate) fn active_decks(&self) -> Vec { - self.tree - .traverse_pre_order(self.tree.root_node_id().unwrap()) - .unwrap() - .map(|node| node.data().deck_id) - .collect() - } - pub(crate) fn decrement_deck_and_parent_limits( &mut self, deck_id: DeckId, diff --git a/rslib/src/scheduler/queue/builder/gathering.rs b/rslib/src/scheduler/queue/builder/gathering.rs index f413c49ab..fb6274de5 100644 --- a/rslib/src/scheduler/queue/builder/gathering.rs +++ b/rslib/src/scheduler/queue/builder/gathering.rs @@ -91,7 +91,7 @@ impl QueueBuilder { col: &mut Collection, sort: NewCardSorting, ) -> Result<()> { - for deck_id in self.limits.active_decks() { + for deck_id in col.storage.get_active_deck_ids_sorted()? { if self.limits.root_limit_reached(LimitKind::New) { break; } diff --git a/rslib/src/storage/deck/active_deck_ids_sorted.sql b/rslib/src/storage/deck/active_deck_ids_sorted.sql new file mode 100644 index 000000000..60c031a33 --- /dev/null +++ b/rslib/src/storage/deck/active_deck_ids_sorted.sql @@ -0,0 +1,7 @@ +SELECT id +FROM decks +WHERE id IN ( + SELECT id + FROM active_decks + ) +ORDER BY name \ No newline at end of file diff --git a/rslib/src/storage/deck/mod.rs b/rslib/src/storage/deck/mod.rs index 1bad0ebb1..7e8d229f4 100644 --- a/rslib/src/storage/deck/mod.rs +++ b/rslib/src/storage/deck/mod.rs @@ -359,6 +359,13 @@ impl SqliteStorage { Ok(()) } + pub(crate) fn get_active_deck_ids_sorted(&self) -> Result> { + self.db + .prepare_cached(include_str!("active_deck_ids_sorted.sql"))? + .query_and_then([], |row| row.get(0).map_err(Into::into))? + .collect() + } + // Upgrading/downgrading/legacy pub(super) fn add_default_deck(&self, tr: &I18n) -> Result<()> {