mirror of
https://github.com/restic/restic.git
synced 2025-08-23 11:23:47 +00:00
implement progress bar for index loading
This commit is contained in:

committed by
Michael Eischer

parent
eac1c4a8d0
commit
ed65a7dbca
@@ -328,7 +328,7 @@ func (d *SnapshotsDirStructure) updateSnapshots(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
err = d.root.repo.LoadIndex(ctx)
|
||||
err = d.root.repo.LoadIndex(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@@ -357,7 +357,7 @@ func TestIndexSave(t *testing.T) {
|
||||
func testIndexSave(t *testing.T, version uint) {
|
||||
repo := createFilledRepo(t, 3, version)
|
||||
|
||||
err := repo.LoadIndex(context.TODO())
|
||||
err := repo.LoadIndex(context.TODO(), nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@@ -213,7 +213,7 @@ func reloadIndex(t *testing.T, repo restic.Repository) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := repo.LoadIndex(context.TODO()); err != nil {
|
||||
if err := repo.LoadIndex(context.TODO(), nil); err != nil {
|
||||
t.Fatalf("error loading new index: %v", err)
|
||||
}
|
||||
}
|
||||
|
@@ -581,15 +581,30 @@ func (r *Repository) SetIndex(i restic.MasterIndex) error {
|
||||
}
|
||||
|
||||
// LoadIndex loads all index files from the backend in parallel and stores them
|
||||
// in the master index. The first error that occurred is returned.
|
||||
func (r *Repository) LoadIndex(ctx context.Context) error {
|
||||
func (r *Repository) LoadIndex(ctx context.Context, p *progress.Counter) error {
|
||||
debug.Log("Loading index")
|
||||
|
||||
if p != nil {
|
||||
var numIndexFiles uint64
|
||||
err := r.List(ctx, restic.IndexFile, func(id restic.ID, size int64) error {
|
||||
numIndexFiles++
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.SetMax(numIndexFiles)
|
||||
defer p.Done()
|
||||
}
|
||||
|
||||
err := index.ForAllIndexes(ctx, r, func(id restic.ID, idx *index.Index, oldFormat bool, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
r.idx.Insert(idx)
|
||||
if p != nil {
|
||||
p.Add(1)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
|
@@ -255,7 +255,7 @@ func TestRepositoryLoadIndex(t *testing.T) {
|
||||
defer cleanup()
|
||||
|
||||
repo := repository.TestOpenLocal(t, repodir)
|
||||
rtest.OK(t, repo.LoadIndex(context.TODO()))
|
||||
rtest.OK(t, repo.LoadIndex(context.TODO(), nil))
|
||||
}
|
||||
|
||||
// loadIndex loads the index id from backend and returns it.
|
||||
@@ -324,7 +324,7 @@ func TestRepositoryLoadUnpackedRetryBroken(t *testing.T) {
|
||||
err = repo.SearchKey(context.TODO(), rtest.TestPassword, 10, "")
|
||||
rtest.OK(t, err)
|
||||
|
||||
rtest.OK(t, repo.LoadIndex(context.TODO()))
|
||||
rtest.OK(t, repo.LoadIndex(context.TODO(), nil))
|
||||
}
|
||||
|
||||
func BenchmarkLoadIndex(b *testing.B) {
|
||||
|
@@ -24,7 +24,7 @@ type Repository interface {
|
||||
Key() *crypto.Key
|
||||
|
||||
Index() MasterIndex
|
||||
LoadIndex(context.Context) error
|
||||
LoadIndex(context.Context, *progress.Counter) error
|
||||
SetIndex(MasterIndex) error
|
||||
LookupBlobSize(ID, BlobType) (uint, bool)
|
||||
|
||||
|
Reference in New Issue
Block a user