repo: Automatically cache tree-only pack files

This commit is contained in:
Alexander Neumann 2017-09-24 22:54:04 +02:00
parent e1dfaf5d87
commit db5ec5d876
1 changed files with 23 additions and 0 deletions

View File

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