Fix review queue if limit is reached (#1855)

This commit is contained in:
RumovZ 2022-05-10 04:11:35 +02:00 committed by GitHub
parent 89530c5f24
commit 6c807c1b2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View File

@ -122,7 +122,9 @@ impl LimitTreeMap {
.unwrap();
let mut map = HashMap::new();
map.insert(root_deck.id, root_id.clone());
if root_limits.limits.review > 0 {
map.insert(root_deck.id, root_id.clone());
}
let mut limits = Self { tree, map };
let mut remaining_decks = child_decks.into_iter().peekable();

View File

@ -287,6 +287,13 @@ mod test {
self.add_or_update_deck(deck).unwrap();
}
fn set_deck_review_limit(&mut self, deck: DeckId, limit: u32) {
let dcid = self.get_deck(deck).unwrap().unwrap().config_id().unwrap();
let mut conf = self.get_deck_config(dcid, false).unwrap().unwrap();
conf.inner.reviews_per_day = limit;
self.add_or_update_deck_config(&mut conf).unwrap();
}
fn queue_as_deck_and_template(&mut self, deck_id: DeckId) -> Vec<(DeckId, u16)> {
self.build_queues(deck_id)
.unwrap()
@ -318,6 +325,18 @@ mod test {
}
}
#[test]
fn should_build_empty_queue_if_limit_is_reached() {
let mut col = open_test_collection();
col.set_config_bool(BoolKey::Sched2021, true, false)
.unwrap();
let note_id = col.add_new_note("Basic").id;
let cids = col.storage.card_ids_of_notes(&[note_id]).unwrap();
col.set_due_date(&cids, "0", None).unwrap();
col.set_deck_review_limit(DeckId(1), 0);
assert_eq!(col.queue_as_deck_and_template(DeckId(1)), vec![]);
}
#[test]
fn new_queue_building() -> Result<()> {
let mut col = open_test_collection();