mirror of
https://git.asonix.dog/asonix/pict-rs
synced 2024-12-22 19:31:35 +00:00
Fix panic when migrating < 100 files, improve resumed migration messaging
This commit is contained in:
parent
3487cb0e30
commit
508dd4340b
1 changed files with 24 additions and 6 deletions
30
src/lib.rs
30
src/lib.rs
|
@ -1496,21 +1496,26 @@ where
|
||||||
S2: Store,
|
S2: Store,
|
||||||
R: IdentifierRepo + HashRepo + SettingsRepo + QueueRepo,
|
R: IdentifierRepo + HashRepo + SettingsRepo + QueueRepo,
|
||||||
{
|
{
|
||||||
let repo_size = repo.size().await?;
|
let mut repo_size = repo.size().await?;
|
||||||
|
|
||||||
tracing::warn!("{repo_size} Hashes will be migrated");
|
let mut progress_opt = repo.get(STORE_MIGRATION_PROGRESS).await?;
|
||||||
|
|
||||||
|
if progress_opt.is_some() {
|
||||||
|
tracing::warn!("Continuing previous migration of {repo_size} total hashes");
|
||||||
|
} else {
|
||||||
|
tracing::warn!("{repo_size} hashes will be migrated");
|
||||||
|
}
|
||||||
|
|
||||||
if repo_size == 0 {
|
if repo_size == 0 {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let pct = repo_size / 100;
|
let mut pct = repo_size / 100;
|
||||||
|
|
||||||
|
// Hashes are read in a consistent order
|
||||||
let stream = repo.hashes().await;
|
let stream = repo.hashes().await;
|
||||||
let mut stream = Box::pin(stream);
|
let mut stream = Box::pin(stream);
|
||||||
|
|
||||||
let mut progress_opt = repo.get(STORE_MIGRATION_PROGRESS).await?;
|
|
||||||
|
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
let mut index = 0;
|
let mut index = 0;
|
||||||
while let Some(hash) = stream.next().await {
|
while let Some(hash) = stream.next().await {
|
||||||
|
@ -1519,8 +1524,21 @@ where
|
||||||
let hash = hash?;
|
let hash = hash?;
|
||||||
|
|
||||||
if let Some(progress) = &progress_opt {
|
if let Some(progress) = &progress_opt {
|
||||||
|
// we've reached the most recently migrated hash.
|
||||||
if progress.as_ref() == hash.as_ref() {
|
if progress.as_ref() == hash.as_ref() {
|
||||||
progress_opt.take();
|
progress_opt.take();
|
||||||
|
|
||||||
|
// update repo size to remaining size
|
||||||
|
repo_size = repo_size.saturating_sub(index);
|
||||||
|
// update pct to be proportional to remainging size
|
||||||
|
pct = repo_size / 100;
|
||||||
|
|
||||||
|
// reset index to 0 for proper percent scaling
|
||||||
|
index = 0;
|
||||||
|
|
||||||
|
tracing::warn!(
|
||||||
|
"Caught up to previous migration's end. {repo_size} hashes will be migrated"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1615,7 +1633,7 @@ where
|
||||||
repo.remove(STORE_MIGRATION_VARIANT).await?;
|
repo.remove(STORE_MIGRATION_VARIANT).await?;
|
||||||
repo.remove(STORE_MIGRATION_MOTION).await?;
|
repo.remove(STORE_MIGRATION_MOTION).await?;
|
||||||
|
|
||||||
if index % pct == 0 {
|
if pct > 0 && index % pct == 0 {
|
||||||
let percent = u32::try_from(index / pct).expect("values 0-100 are always in u32 range");
|
let percent = u32::try_from(index / pct).expect("values 0-100 are always in u32 range");
|
||||||
if percent == 0 {
|
if percent == 0 {
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in a new issue