diff --git a/rslib/src/storage/card/mod.rs b/rslib/src/storage/card/mod.rs index 3a5066ff4..e213a0ecb 100644 --- a/rslib/src/storage/card/mod.rs +++ b/rslib/src/storage/card/mod.rs @@ -836,9 +836,17 @@ impl fmt::Display for ReviewOrderSubclause { let today = timing.days_elapsed; let next_day_at = timing.next_day_at.0; let now = timing.now.0; - temp_string = - format!("extract_fsrs_relative_retrievability(data, case when odue !=0 then odue else due end, {today}, ivl, {next_day_at}, {now}) {order}"); - &temp_string + if *order == SqlSortOrder::Ascending { + // Use relative retrievability to give higher priority to high DR cards, + // while selecting the most overdue ones first + temp_string = + format!("extract_fsrs_relative_retrievability(data, case when odue !=0 then odue else due end, {today}, ivl, {next_day_at}, {now}) asc"); + &temp_string + } else { + temp_string = + format!("extract_fsrs_retrievability(data, case when odue !=0 then odue else due end, ivl, {today}, {next_day_at}, {now}) desc"); + &temp_string + } } ReviewOrderSubclause::Added => "nid asc, ord asc", ReviewOrderSubclause::ReverseAdded => "nid desc, ord asc", diff --git a/rslib/src/storage/sqlite.rs b/rslib/src/storage/sqlite.rs index 3ce1baff0..10c468af2 100644 --- a/rslib/src/storage/sqlite.rs +++ b/rslib/src/storage/sqlite.rs @@ -651,7 +651,7 @@ impl SqliteStorage { } } -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq)] pub enum SqlSortOrder { Ascending, Descending, @@ -677,7 +677,10 @@ mod test { use crate::storage::card::ReviewOrderSubclause; #[test] - fn missing_memory_state_falls_back_to_sm2() -> Result<()> { + // Ascending R uses relative R, which can be approximated using ivl + // and elapsed days. + // Descending R uses pure R, which can't be approximated. + fn missing_memory_state_falls_back_to_sm2_for_asc_r() -> Result<()> { let (mut col, _cids) = v3_test_collection(1)?; col.set_config_bool(BoolKey::Fsrs, true, true)?; col.answer_easy();