Refactor card property fixing logic to use CardFixStats struct

This commit is contained in:
Jarrett Ye 2025-08-04 14:54:47 +08:00
parent a39f6deede
commit 86bbc2c17e
No known key found for this signature in database
GPG key ID: EBFC55E0C1A352BB
2 changed files with 22 additions and 6 deletions

View file

@ -24,6 +24,7 @@ use crate::notetype::NotetypeId;
use crate::notetype::NotetypeKind; use crate::notetype::NotetypeKind;
use crate::prelude::*; use crate::prelude::*;
use crate::progress::ThrottlingProgressHandler; use crate::progress::ThrottlingProgressHandler;
use crate::storage::card::CardFixStats;
use crate::timestamp::TimestampMillis; use crate::timestamp::TimestampMillis;
use crate::timestamp::TimestampSecs; use crate::timestamp::TimestampSecs;
@ -164,15 +165,19 @@ impl Collection {
fn check_card_properties(&mut self, out: &mut CheckDatabaseOutput) -> Result<()> { fn check_card_properties(&mut self, out: &mut CheckDatabaseOutput) -> Result<()> {
let timing = self.timing_today()?; 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, timing.days_elapsed,
TimestampSecs::now(), TimestampSecs::now(),
self.usn()?, self.usn()?,
self.scheduler_version() == SchedulerVersion::V1, self.scheduler_version() == SchedulerVersion::V1,
)?; )?;
out.card_position_too_high = new_cnt; out.card_position_too_high = new_cards_fixed;
out.card_properties_invalid += other_cnt; out.card_properties_invalid += other_cards_fixed;
out.card_last_review_time_empty = last_review_time_cnt; out.card_last_review_time_empty = last_review_time_fixed;
Ok(()) Ok(())
} }

View file

@ -43,6 +43,13 @@ use crate::timestamp::TimestampMillis;
use crate::timestamp::TimestampSecs; use crate::timestamp::TimestampSecs;
use crate::types::Usn; 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 { impl FromSql for CardType {
fn column_result(value: ValueRef<'_>) -> result::Result<Self, FromSqlError> { fn column_result(value: ValueRef<'_>) -> result::Result<Self, FromSqlError> {
if let ValueRef::Integer(i) = value { if let ValueRef::Integer(i) = value {
@ -366,7 +373,7 @@ impl super::SqliteStorage {
mtime: TimestampSecs, mtime: TimestampSecs,
usn: Usn, usn: Usn,
v1_sched: bool, v1_sched: bool,
) -> Result<(usize, usize, usize)> { ) -> Result<CardFixStats> {
let new_cnt = self let new_cnt = self
.db .db
.prepare(include_str!("fix_due_new.sql"))? .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> { pub(crate) fn delete_orphaned_cards(&self) -> Result<usize> {