Fix invalid ids on import (#2449)

This commit is contained in:
RumovZ 2023-03-19 22:04:59 +01:00 committed by GitHub
parent 07217e87e0
commit fdfa33fea4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 13 deletions

View File

@ -144,7 +144,7 @@ impl Collection {
self.update_next_new_position()?;
debug!("invalid ids");
self.maybe_fix_invalid_ids(&mut out)?;
out.invalid_ids = self.maybe_fix_invalid_ids()?;
debug!("db check finished: {:#?}", out);
@ -416,15 +416,15 @@ impl Collection {
self.set_next_card_position(pos)
}
fn maybe_fix_invalid_ids(&mut self, out: &mut CheckDatabaseOutput) -> Result<()> {
pub(crate) fn maybe_fix_invalid_ids(&mut self) -> Result<usize> {
let now = TimestampMillis::now();
let tomorrow = now.adding_secs(24 * 60 * 60).0;
out.invalid_ids = self.storage.invalid_ids(tomorrow)?;
if out.invalid_ids > 0 {
let num_invalid_ids = self.storage.invalid_ids(tomorrow)?;
if num_invalid_ids > 0 {
self.storage.fix_invalid_ids(tomorrow, now.0)?;
self.set_schema_modified()?;
}
Ok(())
Ok(num_invalid_ids)
}
}

View File

@ -137,7 +137,6 @@ pub enum ImportError {
TooNew,
MediaImportFailed { info: String },
NoFieldColumn,
InvalidId,
}
impl ImportError {
@ -149,7 +148,6 @@ impl ImportError {
tr.importing_failed_to_import_media_file(info)
}
ImportError::NoFieldColumn => tr.importing_file_must_contain_field_column(),
ImportError::InvalidId => tr.errors_invalid_ids(),
}
.into()
}

View File

@ -20,7 +20,6 @@ use crate::error::FileIoSnafu;
use crate::error::FileOp;
use crate::import_export::gather::ExchangeData;
use crate::import_export::package::Meta;
use crate::import_export::ImportError;
use crate::import_export::ImportProgress;
use crate::import_export::IncrementableProgress;
use crate::import_export::NoteLog;
@ -107,15 +106,12 @@ impl ExchangeData {
) -> Result<Self> {
let tempfile = collection_to_tempfile(meta, archive)?;
let mut col = CollectionBuilder::new(tempfile.path()).build()?;
col.maybe_fix_invalid_ids()?;
col.maybe_upgrade_scheduler()?;
progress.call(ImportProgress::Gathering)?;
let mut data = ExchangeData::default();
data.gather_data(&mut col, search, with_scheduling)
.map_err(|error| match error {
AnkiError::InvalidId => ImportError::InvalidId.into(),
error => error,
})?;
data.gather_data(&mut col, search, with_scheduling)?;
Ok(data)
}