From 9cf59e4a5de7fe93df486f7bfcc34cb8888946de Mon Sep 17 00:00:00 2001 From: user1823 <92206575+user1823@users.noreply.github.com> Date: Tue, 6 Jan 2026 23:50:35 +0530 Subject: [PATCH] Prevent "not at top of queue" error Because take_while was replaced by filter in intraday_now_iter, the learning card that is shown first may not be at the top of the queue. --- rslib/src/scheduler/queue/mod.rs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/rslib/src/scheduler/queue/mod.rs b/rslib/src/scheduler/queue/mod.rs index 1352d6735..f869fd85a 100644 --- a/rslib/src/scheduler/queue/mod.rs +++ b/rslib/src/scheduler/queue/mod.rs @@ -159,17 +159,13 @@ impl CardQueues { /// Remove the provided card from the top of the queues and /// adjust the counts. If it was not at the top, return an error. fn pop_entry(&mut self, id: CardId) -> Result { - // This ignores the current cutoff, so may match if the provided - // learning card is not yet due. It should not happen in normal - // practice, but does happen in the Python unit tests, as they answer - // learning cards early. - if self - .intraday_learning - .front() - .filter(|e| e.id == id) - .is_some() - { - Ok(self.pop_intraday_learning().unwrap().into()) + if let Some(pos) = self.intraday_learning.iter().position(|e| e.id == id) { + let entry = self.intraday_learning.remove(pos).unwrap(); + // FIXME: + // under normal circumstances this should not go below 0, but currently + // the Python unit tests answer learning cards before they're due + self.counts.learning = self.counts.learning.saturating_sub(1); + Ok(entry.into()) } else if self.main.front().filter(|e| e.id == id).is_some() { Ok(self.pop_main().unwrap().into()) } else {