Save dr and decay in card even if item is None (#4106)

* Document the purpose of storing dr and decay in card

* Format

* Fix type mismatch errors

* Update memory_state.rs

* Save dr and decay in card even if item is None

* Format

* Fix mismatched types

* Update memory_state.rs
This commit is contained in:
user1823 2025-06-21 17:46:54 +05:30 committed by GitHub
parent 88538d8bad
commit c28306eb94
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -105,10 +105,14 @@ impl Collection {
progress.update(true, |state| state.current_cards = idx as u32 + 1)?;
let mut card = self.storage.get_card(card_id)?.or_not_found(card_id)?;
let original = card.clone();
if let (Some(req), Some(item)) = (&req, item) {
card.set_memory_state(&fsrs, Some(item), historical_retention.unwrap())?;
if let Some(req) = &req {
// Store decay and desired retention in the card so that add-ons, card info,
// stats and browser search/sorts don't need to access the deck config.
// Unlike memory states, scheduler doesn't use decay and dr stored in the card.
card.desired_retention = desired_retention;
card.decay = decay;
if let Some(item) = item {
card.set_memory_state(&fsrs, Some(item), historical_retention.unwrap())?;
// if rescheduling
if let Some(reviews) = &last_revlog_info {
// and we have a last review time for the card
@ -128,7 +132,7 @@ impl Collection {
let original_interval = card.interval;
let interval = fsrs.next_interval(
Some(state.stability),
card.desired_retention.unwrap(),
desired_retention.unwrap(),
0,
);
card.interval = rescheduler
@ -156,7 +160,8 @@ impl Collection {
} else {
&mut card.due
};
let new_due = (timing.days_elapsed as i32) - days_elapsed
let new_due = (timing.days_elapsed as i32)
- days_elapsed
+ card.interval as i32;
if let Some(rescheduler) = &mut rescheduler {
rescheduler.update_due_cnt_per_day(
@ -167,15 +172,25 @@ impl Collection {
}
*due = new_due;
// Add a rescheduled revlog entry
self.log_rescheduled_review(&card, original_interval, usn)?;
self.log_rescheduled_review(
&card,
original_interval,
usn,
)?;
}
}
}
}
}
} else {
// clear memory states if item is None
card.memory_state = None;
}
} else {
// clear FSRS data if FSRS is disabled
card.memory_state = None;
card.desired_retention = None;
card.decay = None;
}
self.update_card_inner(&mut card, original, usn)?;
}
@ -213,8 +228,6 @@ impl Collection {
decay,
})
} else {
card.memory_state = None;
card.desired_retention = None;
Ok(ComputeMemoryStateResponse {
state: None,
desired_retention,