From 5e7cf1f9df5b2f02cc03d7ee795a95978b7b22a8 Mon Sep 17 00:00:00 2001 From: user1823 <92206575+user1823@users.noreply.github.com> Date: Tue, 6 Jan 2026 18:07:21 +0530 Subject: [PATCH] Update iterators to use filter instead of take_while After the changes in sort_learning, the learning queue is no longer sorted purely by the due timestamp when the queue contains never-attempted cards. This breaks take_while and skip_while, which stop at the first card that doesn't match the condition, potentially skipping cards that are actually due now. Using filter has a potential performance impact because all intraday learning cards must now be processed instead of just the ones that are within the cutoff. But, in practice, the impact is negligible because filtering is extremely fast and manual testing with large queues showed no noticeable difference. The correct behavior is worth the minimal trade-off. --- rslib/src/scheduler/queue/learning.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/rslib/src/scheduler/queue/learning.rs b/rslib/src/scheduler/queue/learning.rs index 8e2d210b4..baed0943d 100644 --- a/rslib/src/scheduler/queue/learning.rs +++ b/rslib/src/scheduler/queue/learning.rs @@ -21,7 +21,7 @@ impl CardQueues { let cutoff = self.current_learning_cutoff; self.intraday_learning .iter() - .take_while(move |e| e.due <= cutoff) + .filter(move |e| e.due <= cutoff) } /// Intraday learning cards that can be shown after the main queue is empty. @@ -30,8 +30,7 @@ impl CardQueues { let ahead_cutoff = self.current_learn_ahead_cutoff(); self.intraday_learning .iter() - .skip_while(move |e| e.due <= cutoff) - .take_while(move |e| e.due <= ahead_cutoff) + .filter(move |e| e.due > cutoff && e.due <= ahead_cutoff) } /// Increase the cutoff to the current time, and increase the learning count @@ -47,8 +46,7 @@ impl CardQueues { let new_learning_cards = self .intraday_learning .iter() - .skip_while(|e| e.due <= last_ahead_cutoff) - .take_while(|e| e.due <= new_ahead_cutoff) + .filter(|e| e.due > last_ahead_cutoff && e.due <= new_ahead_cutoff) .count(); self.counts.learning += new_learning_cards;