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.
This commit is contained in:
user1823 2026-01-06 23:50:35 +05:30 committed by GitHub
parent bef595ae13
commit 9cf59e4a5d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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<QueueEntry> {
// 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 {