From 1297beff634358576d73325eb955ca7a01302bb4 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 5 May 2022 12:23:05 +1000 Subject: [PATCH] Minor progress tweaks to apkg importing - Set progress as soon as possible; previously the extracting and gathering steps happened prior to the first progress. - Add "extracting" and "gathering" progress steps, so that large imports show more feedback in the early stage, and can be more quickly interrupted. --- ftl/core/importing.ftl | 2 ++ rslib/src/backend/progress.rs | 2 ++ rslib/src/import_export/mod.rs | 2 ++ rslib/src/import_export/package/apkg/import/mod.rs | 7 +++++-- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/ftl/core/importing.ftl b/ftl/core/importing.ftl index 27077eabc..7bd57718f 100644 --- a/ftl/core/importing.ftl +++ b/ftl/core/importing.ftl @@ -79,6 +79,8 @@ importing-processed-media-file = } importing-importing-collection = Importing collection... importing-importing-file = Importing file... +importing-extracting = Extracting data... +importing-gathering = Gathering data... importing-failed-to-import-media-file = Failed to import media file: { $debugInfo } importing-processed-notes = { $count -> diff --git a/rslib/src/backend/progress.rs b/rslib/src/backend/progress.rs index 733d06a67..c259af2bb 100644 --- a/rslib/src/backend/progress.rs +++ b/rslib/src/backend/progress.rs @@ -112,6 +112,8 @@ pub(super) fn progress_to_proto(progress: Option, tr: &I18n) -> pb::Pr ImportProgress::Media(n) => tr.importing_processed_media_file(n), ImportProgress::MediaCheck(n) => tr.media_check_checked(n), ImportProgress::Notes(n) => tr.importing_processed_notes(n), + ImportProgress::Extracting => tr.importing_extracting(), + ImportProgress::Gathering => tr.importing_gathering(), } .into(), ), diff --git a/rslib/src/import_export/mod.rs b/rslib/src/import_export/mod.rs index b1e2944af..b7d5098d5 100644 --- a/rslib/src/import_export/mod.rs +++ b/rslib/src/import_export/mod.rs @@ -12,6 +12,8 @@ use crate::prelude::*; #[derive(Debug, Clone, Copy, PartialEq)] pub enum ImportProgress { File, + Extracting, + Gathering, Media(usize), MediaCheck(usize), Notes(usize), diff --git a/rslib/src/import_export/package/apkg/import/mod.rs b/rslib/src/import_export/package/apkg/import/mod.rs index 810325b7e..c25bb1bb3 100644 --- a/rslib/src/import_export/package/apkg/import/mod.rs +++ b/rslib/src/import_export/package/apkg/import/mod.rs @@ -56,12 +56,14 @@ impl<'a> Context<'a> { target_col: &'a mut Collection, progress_fn: impl 'static + FnMut(ImportProgress, bool) -> bool, ) -> Result { - let progress = IncrementableProgress::new(progress_fn); + let mut progress = IncrementableProgress::new(progress_fn); + progress.call(ImportProgress::Extracting)?; let meta = Meta::from_archive(&mut archive)?; let data = ExchangeData::gather_from_archive( &mut archive, &meta, SearchNode::WholeCollection, + &mut progress, true, )?; let usn = target_col.usn()?; @@ -77,7 +79,6 @@ impl<'a> Context<'a> { fn import(&mut self) -> Result { let mut media_map = self.prepare_media()?; - self.progress.call(ImportProgress::File)?; let note_imports = self.import_notes_and_notetypes(&mut media_map)?; let imported_decks = self.import_decks_and_configs()?; self.import_cards_and_revlog(¬e_imports.id_map, &imported_decks)?; @@ -91,12 +92,14 @@ impl ExchangeData { archive: &mut ZipArchive, meta: &Meta, search: impl TryIntoSearch, + progress: &mut IncrementableProgress, with_scheduling: bool, ) -> Result { let tempfile = collection_to_tempfile(meta, archive)?; let mut col = CollectionBuilder::new(tempfile.path()).build()?; col.maybe_upgrade_scheduler()?; + progress.call(ImportProgress::Gathering)?; let mut data = ExchangeData::default(); data.gather_data(&mut col, search, with_scheduling)?;