handle preview repeat in deck list
This commit is contained in:
parent
186ff1f185
commit
a1866e72fd
@ -19,12 +19,7 @@ impl Collection {
|
|||||||
learn_cutoff: u32,
|
learn_cutoff: u32,
|
||||||
limit_to: Option<&str>,
|
limit_to: Option<&str>,
|
||||||
) -> Result<HashMap<DeckID, DueCounts>> {
|
) -> Result<HashMap<DeckID, DueCounts>> {
|
||||||
if let Some(limit) = limit_to {
|
self.storage
|
||||||
self.storage
|
.due_counts(self.sched_ver(), days_elapsed, learn_cutoff, limit_to)
|
||||||
.due_counts_limited(self.sched_ver(), days_elapsed, learn_cutoff, limit)
|
|
||||||
} else {
|
|
||||||
self.storage
|
|
||||||
.due_counts(self.sched_ver(), days_elapsed, learn_cutoff)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,33 +1,36 @@
|
|||||||
select
|
select did,
|
||||||
did,
|
sum(queue = :new_queue),
|
||||||
-- new
|
|
||||||
sum(queue = ?1),
|
|
||||||
-- reviews
|
|
||||||
sum(
|
sum(
|
||||||
queue = ?2
|
queue = :review_queue
|
||||||
and due <= ?3
|
and due <= :day_cutoff
|
||||||
),
|
),
|
||||||
-- learning
|
-- learning
|
||||||
sum(
|
sum(
|
||||||
(
|
(
|
||||||
case
|
case
|
||||||
-- v2 scheduler
|
:sched_ver
|
||||||
?4
|
|
||||||
when 2 then (
|
when 2 then (
|
||||||
queue = ?5
|
-- v2 scheduler
|
||||||
and due < ?6
|
(
|
||||||
)
|
queue = :learn_queue
|
||||||
or (
|
and due < :learn_cutoff
|
||||||
queue = ?7
|
)
|
||||||
and due <= ?3
|
or (
|
||||||
|
queue = :daylearn_queue
|
||||||
|
and due <= :day_cutoff
|
||||||
|
)
|
||||||
|
or (
|
||||||
|
queue = :preview_queue
|
||||||
|
and due <= :learn_cutoff
|
||||||
|
)
|
||||||
)
|
)
|
||||||
else (
|
else (
|
||||||
-- v1 scheduler
|
-- v1 scheduler
|
||||||
case
|
case
|
||||||
when queue = ?5
|
when queue = :learn_queue
|
||||||
and due < ?6 then left / 1000
|
and due < :learn_cutoff then left / 1000
|
||||||
when queue = ?7
|
when queue = :daylearn_queue
|
||||||
and due <= ?3 then 1
|
and due <= :day_cutoff then 1
|
||||||
else 0
|
else 0
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
@ -35,5 +38,4 @@ select
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
from cards
|
from cards
|
||||||
where
|
where queue >= 0
|
||||||
queue >= 0
|
|
@ -13,7 +13,7 @@ use crate::{
|
|||||||
timestamp::TimestampMillis,
|
timestamp::TimestampMillis,
|
||||||
};
|
};
|
||||||
use prost::Message;
|
use prost::Message;
|
||||||
use rusqlite::{params, Row, NO_PARAMS};
|
use rusqlite::{named_params, params, Row, NO_PARAMS};
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
use unicase::UniCase;
|
use unicase::UniCase;
|
||||||
|
|
||||||
@ -173,54 +173,48 @@ impl SqliteStorage {
|
|||||||
sched: SchedulerVersion,
|
sched: SchedulerVersion,
|
||||||
day_cutoff: u32,
|
day_cutoff: u32,
|
||||||
learn_cutoff: u32,
|
learn_cutoff: u32,
|
||||||
|
top_deck: Option<&str>,
|
||||||
) -> Result<HashMap<DeckID, DueCounts>> {
|
) -> Result<HashMap<DeckID, DueCounts>> {
|
||||||
self.db
|
let sched_ver = sched as u8;
|
||||||
.prepare_cached(concat!(include_str!("due_counts.sql"), " group by did"))?
|
let mut params = named_params! {
|
||||||
.query_and_then(
|
":new_queue": CardQueue::New as u8,
|
||||||
params![
|
":review_queue": CardQueue::Review as u8,
|
||||||
CardQueue::New as u8,
|
":day_cutoff": day_cutoff,
|
||||||
CardQueue::Review as u8,
|
":sched_ver": sched_ver,
|
||||||
day_cutoff,
|
":learn_queue": CardQueue::Learn as u8,
|
||||||
sched as u8,
|
":learn_cutoff": learn_cutoff,
|
||||||
CardQueue::Learn as u8,
|
":daylearn_queue": CardQueue::DayLearn as u8,
|
||||||
learn_cutoff,
|
":preview_queue": CardQueue::PreviewRepeat as u8,
|
||||||
CardQueue::DayLearn as u8,
|
}
|
||||||
],
|
.to_vec();
|
||||||
row_to_due_counts,
|
|
||||||
)?
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn due_counts_limited(
|
let sql;
|
||||||
&self,
|
let prefix_start;
|
||||||
sched: SchedulerVersion,
|
let prefix_end;
|
||||||
day_cutoff: u32,
|
let top;
|
||||||
learn_cutoff: u32,
|
if let Some(top_inner) = top_deck {
|
||||||
top: &str,
|
// limited to deck node
|
||||||
) -> Result<HashMap<DeckID, DueCounts>> {
|
top = top_inner;
|
||||||
let prefix_start = format!("{}\x1f", top);
|
prefix_start = format!("{}\x1f", top);
|
||||||
let prefix_end = format!("{}\x20", top);
|
prefix_end = format!("{}\x20", top);
|
||||||
self.db
|
params.extend(named_params! {
|
||||||
.prepare_cached(concat!(
|
":top_deck": top,
|
||||||
|
":prefix_start": prefix_start,
|
||||||
|
":prefix_end": prefix_end,
|
||||||
|
});
|
||||||
|
sql = concat!(
|
||||||
include_str!("due_counts.sql"),
|
include_str!("due_counts.sql"),
|
||||||
" and did in (select id from decks where name = ? ",
|
" and did in (select id from decks where name = :top_deck ",
|
||||||
"or (name >= ? and name < ?)) group by did "
|
"or (name >= :prefix_start and name < :prefix_end)) group by did "
|
||||||
))?
|
);
|
||||||
.query_and_then(
|
} else {
|
||||||
params![
|
// entire tree
|
||||||
CardQueue::New as u8,
|
sql = concat!(include_str!("due_counts.sql"), " group by did");
|
||||||
CardQueue::Review as u8,
|
}
|
||||||
day_cutoff,
|
|
||||||
sched as u8,
|
self.db
|
||||||
CardQueue::Learn as u8,
|
.prepare_cached(sql)?
|
||||||
learn_cutoff,
|
.query_and_then_named(¶ms, row_to_due_counts)?
|
||||||
CardQueue::DayLearn as u8,
|
|
||||||
top,
|
|
||||||
prefix_start,
|
|
||||||
prefix_end,
|
|
||||||
],
|
|
||||||
row_to_due_counts,
|
|
||||||
)?
|
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user