mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
move cards out of the new queue on filtered deck upgrade
This commit is contained in:
parent
b8acf11f3e
commit
c0b9285923
3 changed files with 35 additions and 39 deletions
|
@ -18,6 +18,22 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
impl Card {
|
impl Card {
|
||||||
|
pub(crate) fn restore_queue_from_type(&mut self) {
|
||||||
|
self.queue = match self.ctype {
|
||||||
|
CardType::Learn | CardType::Relearn => {
|
||||||
|
if self.due > 1_000_000_000 {
|
||||||
|
// unix timestamp
|
||||||
|
CardQueue::Learn
|
||||||
|
} else {
|
||||||
|
// day number
|
||||||
|
CardQueue::DayLearn
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CardType::New => CardQueue::New,
|
||||||
|
CardType::Review => CardQueue::Review,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn move_into_filtered_deck(&mut self, ctx: &DeckFilterContext, position: i32) {
|
pub(crate) fn move_into_filtered_deck(&mut self, ctx: &DeckFilterContext, position: i32) {
|
||||||
// filtered and v1 learning cards are excluded, so odue should be guaranteed to be zero
|
// filtered and v1 learning cards are excluded, so odue should be guaranteed to be zero
|
||||||
if self.original_due != 0 {
|
if self.original_due != 0 {
|
||||||
|
@ -64,17 +80,6 @@ impl Card {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns original_due if set, else due.
|
|
||||||
/// original_due will be set in filtered decks, and in relearning in
|
|
||||||
/// the old scheduler.
|
|
||||||
pub(crate) fn original_or_current_due(&self) -> i32 {
|
|
||||||
if self.original_due > 0 {
|
|
||||||
self.original_due
|
|
||||||
} else {
|
|
||||||
self.due
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn original_or_current_deck_id(&self) -> DeckID {
|
pub(crate) fn original_or_current_deck_id(&self) -> DeckID {
|
||||||
if self.original_deck_id.0 > 0 {
|
if self.original_deck_id.0 > 0 {
|
||||||
self.original_deck_id
|
self.original_deck_id
|
||||||
|
@ -116,19 +121,7 @@ impl Card {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.queue as i8) >= 0 {
|
if (self.queue as i8) >= 0 {
|
||||||
self.queue = match self.ctype {
|
self.restore_queue_from_type();
|
||||||
CardType::Learn | CardType::Relearn => {
|
|
||||||
if self.due > 1_000_000_000 {
|
|
||||||
// unix timestamp
|
|
||||||
CardQueue::Learn
|
|
||||||
} else {
|
|
||||||
// day number
|
|
||||||
CardQueue::DayLearn
|
|
||||||
}
|
|
||||||
}
|
|
||||||
CardType::New => CardQueue::New,
|
|
||||||
CardType::Review => CardQueue::Review,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
backend_proto as pb,
|
backend_proto as pb,
|
||||||
card::{Card, CardID, CardQueue, CardType},
|
card::{Card, CardID, CardQueue},
|
||||||
collection::Collection,
|
collection::Collection,
|
||||||
config::SchedulerVersion,
|
config::SchedulerVersion,
|
||||||
err::Result,
|
err::Result,
|
||||||
|
@ -22,19 +22,7 @@ impl Card {
|
||||||
) {
|
) {
|
||||||
false
|
false
|
||||||
} else {
|
} else {
|
||||||
self.queue = match self.ctype {
|
self.restore_queue_from_type();
|
||||||
CardType::Learn | CardType::Relearn => {
|
|
||||||
if self.original_or_current_due() > 1_000_000_000 {
|
|
||||||
// previous interval was in seconds
|
|
||||||
CardQueue::Learn
|
|
||||||
} else {
|
|
||||||
// previous interval was in days
|
|
||||||
CardQueue::DayLearn
|
|
||||||
}
|
|
||||||
}
|
|
||||||
CardType::New => CardQueue::New,
|
|
||||||
CardType::Review => CardQueue::Review,
|
|
||||||
};
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,12 @@ impl Card {
|
||||||
self.remaining_steps = self.remaining_steps.min(step_count);
|
self.remaining_steps = self.remaining_steps.min(step_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
if !info.reschedule {
|
if info.reschedule {
|
||||||
|
// only new cards should be in the new queue
|
||||||
|
if self.queue == CardQueue::New && self.ctype != CardType::New {
|
||||||
|
self.restore_queue_from_type();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
// preview cards start in the review queue in v2
|
// preview cards start in the review queue in v2
|
||||||
if self.queue == CardQueue::New {
|
if self.queue == CardQueue::New {
|
||||||
self.queue = CardQueue::Review;
|
self.queue = CardQueue::Review;
|
||||||
|
@ -182,5 +187,15 @@ mod test {
|
||||||
}));
|
}));
|
||||||
assert_eq!(c.ctype, CardType::New);
|
assert_eq!(c.ctype, CardType::New);
|
||||||
assert_eq!(c.queue, CardQueue::PreviewRepeat);
|
assert_eq!(c.queue, CardQueue::PreviewRepeat);
|
||||||
|
|
||||||
|
// (early) reviews should be moved back from the new queue
|
||||||
|
c.ctype = CardType::Review;
|
||||||
|
c.queue = CardQueue::New;
|
||||||
|
c.upgrade_to_v2(Some(V1FilteredDeckInfo {
|
||||||
|
reschedule: true,
|
||||||
|
original_step_count: None,
|
||||||
|
}));
|
||||||
|
assert_eq!(c.ctype, CardType::Review);
|
||||||
|
assert_eq!(c.queue, CardQueue::Review);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue