mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
Clear memory state when user disables FSRS
This commit is contained in:
parent
75de1f9709
commit
25d5e56397
2 changed files with 19 additions and 12 deletions
|
@ -204,7 +204,7 @@ impl Collection {
|
|||
.map(|c| c.inner.fsrs_enabled)
|
||||
.unwrap_or_default();
|
||||
let current_weights = current_config.map(|c| &c.inner.fsrs_weights);
|
||||
if current_fsrs_on && (!previous_fsrs_on || previous_weights != current_weights) {
|
||||
if current_fsrs_on != previous_fsrs_on || previous_weights != current_weights {
|
||||
decks_needing_memory_recompute
|
||||
.entry(current_config_id)
|
||||
.or_default()
|
||||
|
@ -216,15 +216,16 @@ impl Collection {
|
|||
}
|
||||
|
||||
if !decks_needing_memory_recompute.is_empty() {
|
||||
let input: Vec<(Weights, Vec<SearchNode>)> = decks_needing_memory_recompute
|
||||
let input: Vec<(Option<Weights>, Vec<SearchNode>)> = decks_needing_memory_recompute
|
||||
.into_iter()
|
||||
.map(|(conf_id, search)| {
|
||||
let weights = configs_after_update
|
||||
.get(&conf_id)
|
||||
.or_not_found(conf_id)?
|
||||
.inner
|
||||
.fsrs_weights
|
||||
.clone();
|
||||
let weights = configs_after_update.get(&conf_id).and_then(|c| {
|
||||
if c.inner.fsrs_enabled {
|
||||
Some(c.inner.fsrs_weights.clone())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
});
|
||||
Ok((weights, search))
|
||||
})
|
||||
.collect::<Result<_>>()?;
|
||||
|
|
|
@ -21,9 +21,11 @@ impl Collection {
|
|||
/// For each provided set of weights, locate cards with the provided search,
|
||||
/// and update their memory state.
|
||||
/// Should be called inside a transaction.
|
||||
/// If Weights are None, it means the user disabled FSRS, and the existing
|
||||
/// memory state should be removed.
|
||||
pub(crate) fn update_memory_state(
|
||||
&mut self,
|
||||
entries: Vec<(Weights, Vec<SearchNode>)>,
|
||||
entries: Vec<(Option<Weights>, Vec<SearchNode>)>,
|
||||
) -> Result<()> {
|
||||
let timing = self.timing_today()?;
|
||||
let usn = self.usn()?;
|
||||
|
@ -32,15 +34,19 @@ impl Collection {
|
|||
.and(SearchNode::State(StateKind::New).negated());
|
||||
let revlog = self.revlog_for_srs(search)?;
|
||||
let items = fsrs_items_for_memory_state(revlog, timing.next_day_at);
|
||||
let fsrs = FSRS::new(Some(&weights))?;
|
||||
let fsrs = FSRS::new(weights.as_deref())?;
|
||||
let mut progress = self.new_progress_handler::<ComputeMemoryProgress>();
|
||||
progress.update(false, |s| s.total_cards = items.len() as u32)?;
|
||||
for (idx, (card_id, item)) in items.into_iter().enumerate() {
|
||||
progress.update(true, |state| state.current_cards = idx as u32 + 1)?;
|
||||
let state = fsrs.memory_state(item);
|
||||
let mut card = self.storage.get_card(card_id)?.or_not_found(card_id)?;
|
||||
let original = card.clone();
|
||||
card.memory_state = Some(state.into());
|
||||
if weights.is_some() {
|
||||
let state = fsrs.memory_state(item);
|
||||
card.memory_state = Some(state.into());
|
||||
} else {
|
||||
card.memory_state = None;
|
||||
}
|
||||
self.update_card_inner(&mut card, original, usn)?;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue