From d752a43e2a528fcbbcfe9e80851193ff85e2c24f Mon Sep 17 00:00:00 2001 From: Abdo Date: Tue, 14 Nov 2023 08:08:36 +0300 Subject: [PATCH] Fix filtered deck ordering of intraday learning cards and reviews (#2828) * Fix filtered deck ordering of intraday learning cards and reviews * Handle rollover correctly --- rslib/src/scheduler/filtered/mod.rs | 2 +- rslib/src/storage/card/filtered.rs | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/rslib/src/scheduler/filtered/mod.rs b/rslib/src/scheduler/filtered/mod.rs index 60083f6ac..31e5cb518 100644 --- a/rslib/src/scheduler/filtered/mod.rs +++ b/rslib/src/scheduler/filtered/mod.rs @@ -121,7 +121,7 @@ impl Collection { format!("({})", term.search) } ); - let order = order_and_limit_for_search(term, ctx.today); + let order = order_and_limit_for_search(term, ctx.today, TimestampSecs::now().0); for mut card in self.all_cards_for_search_in_order(&search, SortMode::Custom(order))? { let original = card.clone(); diff --git a/rslib/src/storage/card/filtered.rs b/rslib/src/storage/card/filtered.rs index d27a5cac6..a84a4fed0 100644 --- a/rslib/src/storage/card/filtered.rs +++ b/rslib/src/storage/card/filtered.rs @@ -5,7 +5,11 @@ use crate::card::CardQueue; use crate::decks::FilteredSearchOrder; use crate::decks::FilteredSearchTerm; -pub(crate) fn order_and_limit_for_search(term: &FilteredSearchTerm, today: u32) -> String { +pub(crate) fn order_and_limit_for_search( + term: &FilteredSearchTerm, + today: u32, + current_timestamp: i64, +) -> String { let temp_string; let order = match term.order() { FilteredSearchOrder::OldestReviewedFirst => "(select max(id) from revlog where cid=c.id)", @@ -15,7 +19,11 @@ pub(crate) fn order_and_limit_for_search(term: &FilteredSearchTerm, today: u32) FilteredSearchOrder::Lapses => "lapses desc", FilteredSearchOrder::Added => "n.id, c.ord", FilteredSearchOrder::ReverseAdded => "n.id desc", - FilteredSearchOrder::Due => "c.due, c.ord", + FilteredSearchOrder::Due => { + temp_string = format!( + "(case when c.due > 1000000000 then due else (due - {today}) * 86400 + {current_timestamp} end), c.ord"); + &temp_string + } FilteredSearchOrder::DuePriority => { temp_string = format!( "