backend: Make pagination for List configurable

This commit is contained in:
Alexander Neumann
2017-09-18 12:01:54 +02:00
parent 649c536250
commit 3b6a580b32
3 changed files with 72 additions and 54 deletions

View File

@@ -17,13 +17,16 @@ import (
// Backend stores data on an azure endpoint.
type Backend struct {
accountName string
container *storage.Container
sem *backend.Semaphore
prefix string
accountName string
container *storage.Container
sem *backend.Semaphore
prefix string
listMaxItems int
backend.Layout
}
const defaultListMaxItems = 5000
// make sure that *Backend implements backend.Backend
var _ restic.Backend = &Backend{}
@@ -53,6 +56,7 @@ func open(cfg Config) (*Backend, error) {
Path: cfg.Prefix,
Join: path.Join,
},
listMaxItems: defaultListMaxItems,
}
return be, nil
@@ -84,6 +88,11 @@ func Create(cfg Config) (restic.Backend, error) {
return be, nil
}
// SetListMaxItems sets the number of list items to load per request.
func (be *Backend) SetListMaxItems(i int) {
be.listMaxItems = i
}
// IsNotExist returns true if the error is caused by a not existing file.
func (be *Backend) IsNotExist(err error) bool {
debug.Log("IsNotExist(%T, %#v)", err, err)
@@ -265,7 +274,7 @@ func (be *Backend) List(ctx context.Context, t restic.FileType) <-chan string {
}
params := storage.ListBlobsParameters{
MaxResults: 1000,
MaxResults: uint(be.listMaxItems),
Prefix: prefix,
}