handle preview repeat in deck list

This commit is contained in:
Damien Elmes 2020-07-30 08:20:51 +10:00
parent 186ff1f185
commit a1866e72fd
3 changed files with 65 additions and 74 deletions

View File

@ -19,12 +19,7 @@ impl Collection {
learn_cutoff: u32,
limit_to: Option<&str>,
) -> Result<HashMap<DeckID, DueCounts>> {
if let Some(limit) = limit_to {
self.storage
.due_counts_limited(self.sched_ver(), days_elapsed, learn_cutoff, limit)
} else {
self.storage
.due_counts(self.sched_ver(), days_elapsed, learn_cutoff)
}
self.storage
.due_counts(self.sched_ver(), days_elapsed, learn_cutoff, limit_to)
}
}

View File

@ -1,33 +1,36 @@
select
did,
-- new
sum(queue = ?1),
-- reviews
select did,
sum(queue = :new_queue),
sum(
queue = ?2
and due <= ?3
queue = :review_queue
and due <= :day_cutoff
),
-- learning
sum(
(
case
-- v2 scheduler
?4
:sched_ver
when 2 then (
queue = ?5
and due < ?6
)
or (
queue = ?7
and due <= ?3
-- v2 scheduler
(
queue = :learn_queue
and due < :learn_cutoff
)
or (
queue = :daylearn_queue
and due <= :day_cutoff
)
or (
queue = :preview_queue
and due <= :learn_cutoff
)
)
else (
-- v1 scheduler
case
when queue = ?5
and due < ?6 then left / 1000
when queue = ?7
and due <= ?3 then 1
when queue = :learn_queue
and due < :learn_cutoff then left / 1000
when queue = :daylearn_queue
and due <= :day_cutoff then 1
else 0
end
)
@ -35,5 +38,4 @@ select
)
)
from cards
where
queue >= 0
where queue >= 0

View File

@ -13,7 +13,7 @@ use crate::{
timestamp::TimestampMillis,
};
use prost::Message;
use rusqlite::{params, Row, NO_PARAMS};
use rusqlite::{named_params, params, Row, NO_PARAMS};
use std::collections::{HashMap, HashSet};
use unicase::UniCase;
@ -173,54 +173,48 @@ impl SqliteStorage {
sched: SchedulerVersion,
day_cutoff: u32,
learn_cutoff: u32,
top_deck: Option<&str>,
) -> Result<HashMap<DeckID, DueCounts>> {
self.db
.prepare_cached(concat!(include_str!("due_counts.sql"), " group by did"))?
.query_and_then(
params![
CardQueue::New as u8,
CardQueue::Review as u8,
day_cutoff,
sched as u8,
CardQueue::Learn as u8,
learn_cutoff,
CardQueue::DayLearn as u8,
],
row_to_due_counts,
)?
.collect()
}
let sched_ver = sched as u8;
let mut params = named_params! {
":new_queue": CardQueue::New as u8,
":review_queue": CardQueue::Review as u8,
":day_cutoff": day_cutoff,
":sched_ver": sched_ver,
":learn_queue": CardQueue::Learn as u8,
":learn_cutoff": learn_cutoff,
":daylearn_queue": CardQueue::DayLearn as u8,
":preview_queue": CardQueue::PreviewRepeat as u8,
}
.to_vec();
pub(crate) fn due_counts_limited(
&self,
sched: SchedulerVersion,
day_cutoff: u32,
learn_cutoff: u32,
top: &str,
) -> Result<HashMap<DeckID, DueCounts>> {
let prefix_start = format!("{}\x1f", top);
let prefix_end = format!("{}\x20", top);
self.db
.prepare_cached(concat!(
let sql;
let prefix_start;
let prefix_end;
let top;
if let Some(top_inner) = top_deck {
// limited to deck node
top = top_inner;
prefix_start = format!("{}\x1f", top);
prefix_end = format!("{}\x20", top);
params.extend(named_params! {
":top_deck": top,
":prefix_start": prefix_start,
":prefix_end": prefix_end,
});
sql = concat!(
include_str!("due_counts.sql"),
" and did in (select id from decks where name = ? ",
"or (name >= ? and name < ?)) group by did "
))?
.query_and_then(
params![
CardQueue::New as u8,
CardQueue::Review as u8,
day_cutoff,
sched as u8,
CardQueue::Learn as u8,
learn_cutoff,
CardQueue::DayLearn as u8,
top,
prefix_start,
prefix_end,
],
row_to_due_counts,
)?
" and did in (select id from decks where name = :top_deck ",
"or (name >= :prefix_start and name < :prefix_end)) group by did "
);
} else {
// entire tree
sql = concat!(include_str!("due_counts.sql"), " group by did");
}
self.db
.prepare_cached(sql)?
.query_and_then_named(&params, row_to_due_counts)?
.collect()
}