mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Support fetching new cards by deck then random note
https://forums.ankiweb.net/t/feature-request-option-for-new-card-gather-order-that-prioritizes-subdecks-closer-to-top-but-gathers-cards-randomly-from-each-subdeck/23178
This commit is contained in:
parent
e6fdfc20a9
commit
9cc4720efe
3 changed files with 33 additions and 13 deletions
|
@ -43,6 +43,9 @@ message DeckConfig {
|
||||||
// Decks in alphabetical order (preorder), then ascending position.
|
// Decks in alphabetical order (preorder), then ascending position.
|
||||||
// Siblings are consecutive, provided they have the same position.
|
// Siblings are consecutive, provided they have the same position.
|
||||||
NEW_CARD_GATHER_PRIORITY_DECK = 0;
|
NEW_CARD_GATHER_PRIORITY_DECK = 0;
|
||||||
|
// Notes are randomly picked from each deck in alphabetical order.
|
||||||
|
// Siblings are consecutive, provided they have the same position.
|
||||||
|
NEW_CARD_GATHER_PRIORITY_DECK_THEN_RANDOM_NOTES = 5;
|
||||||
// Ascending position.
|
// Ascending position.
|
||||||
// Siblings are consecutive, provided they have the same position.
|
// Siblings are consecutive, provided they have the same position.
|
||||||
NEW_CARD_GATHER_PRIORITY_LOWEST_POSITION = 1;
|
NEW_CARD_GATHER_PRIORITY_LOWEST_POSITION = 1;
|
||||||
|
|
|
@ -62,7 +62,13 @@ impl QueueBuilder {
|
||||||
|
|
||||||
fn gather_new_cards(&mut self, col: &mut Collection) -> Result<()> {
|
fn gather_new_cards(&mut self, col: &mut Collection) -> Result<()> {
|
||||||
match self.context.sort_options.new_gather_priority {
|
match self.context.sort_options.new_gather_priority {
|
||||||
NewCardGatherPriority::Deck => self.gather_new_cards_by_deck(col),
|
NewCardGatherPriority::Deck => {
|
||||||
|
self.gather_new_cards_by_deck(col, NewCardSorting::LowestPosition)
|
||||||
|
}
|
||||||
|
NewCardGatherPriority::DeckThenRandomNotes => self.gather_new_cards_by_deck(
|
||||||
|
col,
|
||||||
|
NewCardSorting::RandomNotes(self.context.timing.days_elapsed),
|
||||||
|
),
|
||||||
NewCardGatherPriority::LowestPosition => {
|
NewCardGatherPriority::LowestPosition => {
|
||||||
self.gather_new_cards_sorted(col, NewCardSorting::LowestPosition)
|
self.gather_new_cards_sorted(col, NewCardSorting::LowestPosition)
|
||||||
}
|
}
|
||||||
|
@ -80,7 +86,11 @@ impl QueueBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gather_new_cards_by_deck(&mut self, col: &mut Collection) -> Result<()> {
|
fn gather_new_cards_by_deck(
|
||||||
|
&mut self,
|
||||||
|
col: &mut Collection,
|
||||||
|
sort: NewCardSorting,
|
||||||
|
) -> Result<()> {
|
||||||
for deck_id in self.limits.active_decks() {
|
for deck_id in self.limits.active_decks() {
|
||||||
if self.limits.root_limit_reached(LimitKind::New) {
|
if self.limits.root_limit_reached(LimitKind::New) {
|
||||||
break;
|
break;
|
||||||
|
@ -88,14 +98,15 @@ impl QueueBuilder {
|
||||||
if self.limits.limit_reached(deck_id, LimitKind::New)? {
|
if self.limits.limit_reached(deck_id, LimitKind::New)? {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
col.storage.for_each_new_card_in_deck(deck_id, |card| {
|
col.storage
|
||||||
let limit_reached = self.limits.limit_reached(deck_id, LimitKind::New)?;
|
.for_each_new_card_in_deck(deck_id, sort, |card| {
|
||||||
if !limit_reached && self.add_new_card(card) {
|
let limit_reached = self.limits.limit_reached(deck_id, LimitKind::New)?;
|
||||||
self.limits
|
if !limit_reached && self.add_new_card(card) {
|
||||||
.decrement_deck_and_parent_limits(deck_id, LimitKind::New)?;
|
self.limits
|
||||||
}
|
.decrement_deck_and_parent_limits(deck_id, LimitKind::New)?;
|
||||||
Ok(!limit_reached)
|
}
|
||||||
})?;
|
Ok(!limit_reached)
|
||||||
|
})?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -289,13 +289,19 @@ impl super::SqliteStorage {
|
||||||
|
|
||||||
/// Call func() for each new card in the provided deck, stopping when it
|
/// Call func() for each new card in the provided deck, stopping when it
|
||||||
/// returns or no more cards found.
|
/// returns or no more cards found.
|
||||||
pub(crate) fn for_each_new_card_in_deck<F>(&self, deck: DeckId, mut func: F) -> Result<()>
|
pub(crate) fn for_each_new_card_in_deck<F>(
|
||||||
|
&self,
|
||||||
|
deck: DeckId,
|
||||||
|
sort: NewCardSorting,
|
||||||
|
mut func: F,
|
||||||
|
) -> Result<()>
|
||||||
where
|
where
|
||||||
F: FnMut(NewCard) -> Result<bool>,
|
F: FnMut(NewCard) -> Result<bool>,
|
||||||
{
|
{
|
||||||
let mut stmt = self.db.prepare_cached(&format!(
|
let mut stmt = self.db.prepare_cached(&format!(
|
||||||
"{} ORDER BY due, ord ASC",
|
"{} ORDER BY {}",
|
||||||
include_str!("new_cards.sql")
|
include_str!("new_cards.sql"),
|
||||||
|
sort.write()
|
||||||
))?;
|
))?;
|
||||||
let mut rows = stmt.query(params![deck])?;
|
let mut rows = stmt.query(params![deck])?;
|
||||||
while let Some(row) = rows.next()? {
|
while let Some(row) = rows.next()? {
|
||||||
|
|
Loading…
Reference in a new issue