mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
Refactor card property fixing logic to use CardFixStats struct
This commit is contained in:
parent
a39f6deede
commit
86bbc2c17e
2 changed files with 22 additions and 6 deletions
|
@ -24,6 +24,7 @@ use crate::notetype::NotetypeId;
|
|||
use crate::notetype::NotetypeKind;
|
||||
use crate::prelude::*;
|
||||
use crate::progress::ThrottlingProgressHandler;
|
||||
use crate::storage::card::CardFixStats;
|
||||
use crate::timestamp::TimestampMillis;
|
||||
use crate::timestamp::TimestampSecs;
|
||||
|
||||
|
@ -164,15 +165,19 @@ impl Collection {
|
|||
|
||||
fn check_card_properties(&mut self, out: &mut CheckDatabaseOutput) -> Result<()> {
|
||||
let timing = self.timing_today()?;
|
||||
let (new_cnt, other_cnt, last_review_time_cnt) = self.storage.fix_card_properties(
|
||||
let CardFixStats {
|
||||
new_cards_fixed,
|
||||
other_cards_fixed,
|
||||
last_review_time_fixed,
|
||||
} = self.storage.fix_card_properties(
|
||||
timing.days_elapsed,
|
||||
TimestampSecs::now(),
|
||||
self.usn()?,
|
||||
self.scheduler_version() == SchedulerVersion::V1,
|
||||
)?;
|
||||
out.card_position_too_high = new_cnt;
|
||||
out.card_properties_invalid += other_cnt;
|
||||
out.card_last_review_time_empty = last_review_time_cnt;
|
||||
out.card_position_too_high = new_cards_fixed;
|
||||
out.card_properties_invalid += other_cards_fixed;
|
||||
out.card_last_review_time_empty = last_review_time_fixed;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -43,6 +43,13 @@ use crate::timestamp::TimestampMillis;
|
|||
use crate::timestamp::TimestampSecs;
|
||||
use crate::types::Usn;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub(crate) struct CardFixStats {
|
||||
pub new_cards_fixed: usize,
|
||||
pub other_cards_fixed: usize,
|
||||
pub last_review_time_fixed: usize,
|
||||
}
|
||||
|
||||
impl FromSql for CardType {
|
||||
fn column_result(value: ValueRef<'_>) -> result::Result<Self, FromSqlError> {
|
||||
if let ValueRef::Integer(i) = value {
|
||||
|
@ -366,7 +373,7 @@ impl super::SqliteStorage {
|
|||
mtime: TimestampSecs,
|
||||
usn: Usn,
|
||||
v1_sched: bool,
|
||||
) -> Result<(usize, usize, usize)> {
|
||||
) -> Result<CardFixStats> {
|
||||
let new_cnt = self
|
||||
.db
|
||||
.prepare(include_str!("fix_due_new.sql"))?
|
||||
|
@ -404,7 +411,11 @@ impl super::SqliteStorage {
|
|||
}
|
||||
}
|
||||
}
|
||||
Ok((new_cnt, other_cnt, last_review_time_cnt))
|
||||
Ok(CardFixStats {
|
||||
new_cards_fixed: new_cnt,
|
||||
other_cards_fixed: other_cnt,
|
||||
last_review_time_fixed: last_review_time_cnt,
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn delete_orphaned_cards(&self) -> Result<usize> {
|
||||
|
|
Loading…
Reference in a new issue