mirror of
https://github.com/ankitects/anki.git
synced 2026-10-02 05:24:38 +08:00
refactor: use col.fsrs_enabled in more places (#5651)
closes #5652 `col.fsrs_enabled` should be usable in any place where we have access to the collection (And that doesn't involve building the queue or modifying the config). c.c. @user1823
This commit is contained in:
@@ -14,7 +14,6 @@ use serde_repr::Deserialize_repr;
|
||||
use serde_repr::Serialize_repr;
|
||||
|
||||
use crate::collection::Collection;
|
||||
use crate::config::BoolKey;
|
||||
use crate::config::SchedulerVersion;
|
||||
use crate::deckconfig::DeckConfig;
|
||||
use crate::decks::DeckId;
|
||||
@@ -378,7 +377,7 @@ impl Collection {
|
||||
source: FilteredDeckError::CanNotMoveCardsInto,
|
||||
})?;
|
||||
let config = self.get_deck_config(config_id, true)?.unwrap();
|
||||
let fsrs_enabled = self.get_config_bool(BoolKey::Fsrs);
|
||||
let fsrs_enabled = self.fsrs_enabled();
|
||||
let mut steps_adjuster = RemainingStepsAdjuster::new(&config);
|
||||
let usn = self.usn()?;
|
||||
self.transact(Op::SetCardDeck, |col| {
|
||||
|
||||
@@ -444,7 +444,7 @@ impl Collection {
|
||||
)
|
||||
}
|
||||
|
||||
fn fsrs_enabled(&self) -> bool {
|
||||
pub fn fsrs_enabled(&self) -> bool {
|
||||
self.state
|
||||
// Card queues are re-built when the deck config is saved so this will be kept up to
|
||||
// date. See: https://github.com/ankitects/anki/blob/acdf486b290bd47d13e2e880fbb1c14773899091/rslib/src/ops.rs#L168-L181
|
||||
|
||||
@@ -103,9 +103,9 @@ impl Collection {
|
||||
fn build_filtered_deck(&mut self, ctx: DeckFilterContext) -> Result<usize> {
|
||||
let start = -100_000;
|
||||
let mut position = start;
|
||||
let fsrs = self.get_config_bool(BoolKey::Fsrs);
|
||||
let fsrs_enabled = self.fsrs_enabled();
|
||||
for term in ctx.config.search_terms.iter().take(2) {
|
||||
position = self.move_cards_matching_term(&ctx, term, position, fsrs)?;
|
||||
position = self.move_cards_matching_term(&ctx, term, position, fsrs_enabled)?;
|
||||
}
|
||||
|
||||
Ok((position - start) as usize)
|
||||
|
||||
@@ -138,7 +138,7 @@ impl Collection {
|
||||
let mut rng = rand::rng();
|
||||
let distribution = Uniform::new_inclusive(spec.min, spec.max).unwrap();
|
||||
let mut decks_initial_ease: HashMap<DeckId, f32> = HashMap::new();
|
||||
let fsrs_enabled = self.get_config_bool(BoolKey::Fsrs);
|
||||
let fsrs_enabled = self.fsrs_enabled();
|
||||
self.transact(Op::SetDueDate, |col| {
|
||||
for mut card in col.all_cards_for_ids(cids, false)? {
|
||||
let deck_id = card.original_deck_id.or(card.deck_id);
|
||||
|
||||
@@ -30,7 +30,7 @@ impl Collection {
|
||||
|
||||
let (average_secs, total_secs) = average_and_total_secs_strings(&revlog);
|
||||
let timing = self.timing_today()?;
|
||||
let fsrs_enabled = card.desired_retention.is_some();
|
||||
let fsrs_enabled = self.fsrs_enabled();
|
||||
|
||||
let last_review_time = if let Some(last_review_time) = card.last_review_time {
|
||||
last_review_time
|
||||
@@ -272,7 +272,7 @@ mod test {
|
||||
let mut card = col.storage.get_card(cid)?.unwrap();
|
||||
assert!(card.memory_state.is_some());
|
||||
|
||||
card.memory_state = None;
|
||||
card.clear_fsrs_data();
|
||||
col.storage.update_card(&card)?;
|
||||
|
||||
let card = col.storage.get_card(cid)?.unwrap();
|
||||
|
||||
@@ -78,7 +78,7 @@ impl Collection {
|
||||
card_counts: Some(ctx.card_counts()),
|
||||
rollover_hour: self.rollover_for_current_scheduler()? as u32,
|
||||
retrievability: Some(ctx.retrievability()),
|
||||
fsrs: self.get_config_bool(BoolKey::Fsrs),
|
||||
fsrs: self.fsrs_enabled(),
|
||||
};
|
||||
Ok(resp)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user