diff --git a/internal/repository/repository.go b/internal/repository/repository.go index ac1e334af..96eb932d9 100644 --- a/internal/repository/repository.go +++ b/internal/repository/repository.go @@ -7,6 +7,7 @@ import ( "fmt" "os" + "github.com/restic/restic/internal/cache" "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/restic" @@ -422,6 +423,28 @@ func (r *Repository) LoadIndex(ctx context.Context) error { if err != nil { fmt.Fprintf(os.Stderr, "error clearing data files in cache: %v\n", err) } + + treePacks := restic.NewIDSet() + for _, idx := range r.idx.All() { + for _, id := range idx.TreePacks() { + treePacks.Insert(id) + } + } + + // use readahead + cache := r.Cache.(*cache.Cache) + cache.PerformReadahead = func(h restic.Handle) bool { + if h.Type != restic.DataFile { + return false + } + + id, err := restic.ParseID(h.Name) + if err != nil { + return false + } + + return treePacks.Has(id) + } } if err := <-errCh; err != nil {