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.
This commit is contained in:
user1823 2026-01-06 18:07:21 +05:30 committed by GitHub
parent fd4e8457d8
commit 5e7cf1f9df
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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;