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.
This commit is contained in:
Damien Elmes 2022-05-05 12:23:05 +10:00
parent bc6ede7c11
commit 1297beff63
4 changed files with 11 additions and 2 deletions

View File

@ -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 ->

View File

@ -112,6 +112,8 @@ pub(super) fn progress_to_proto(progress: Option<Progress>, 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(),
),

View File

@ -12,6 +12,8 @@ use crate::prelude::*;
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum ImportProgress {
File,
Extracting,
Gathering,
Media(usize),
MediaCheck(usize),
Notes(usize),

View File

@ -56,12 +56,14 @@ impl<'a> Context<'a> {
target_col: &'a mut Collection,
progress_fn: impl 'static + FnMut(ImportProgress, bool) -> bool,
) -> Result<Self> {
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<NoteLog> {
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(&note_imports.id_map, &imported_decks)?;
@ -91,12 +92,14 @@ impl ExchangeData {
archive: &mut ZipArchive<File>,
meta: &Meta,
search: impl TryIntoSearch,
progress: &mut IncrementableProgress<ImportProgress>,
with_scheduling: bool,
) -> Result<Self> {
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)?;