From 835ba16c275a983bd2b4b8c80eea3399cd6a3acd Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Mon, 18 Sep 2017 12:13:35 +0200 Subject: [PATCH] b2: Add pagination for List() --- internal/backend/b2/b2.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/internal/backend/b2/b2.go b/internal/backend/b2/b2.go index 94a13222b..8fd148769 100644 --- a/internal/backend/b2/b2.go +++ b/internal/backend/b2/b2.go @@ -16,13 +16,16 @@ import ( // b2Backend is a backend which stores its data on Backblaze B2. type b2Backend struct { - client *b2.Client - bucket *b2.Bucket - cfg Config + client *b2.Client + bucket *b2.Bucket + cfg Config + listMaxItems int backend.Layout sem *backend.Semaphore } +const defaultListMaxItems = 1000 + // ensure statically that *b2Backend implements restic.Backend. var _ restic.Backend = &b2Backend{} @@ -121,6 +124,11 @@ func Create(cfg Config) (restic.Backend, error) { return be, nil } +// SetListMaxItems sets the number of list items to load per request. +func (be *b2Backend) SetListMaxItems(i int) { + be.listMaxItems = i +} + // Location returns the location for the backend. func (be *b2Backend) Location() string { return be.cfg.Bucket @@ -307,10 +315,11 @@ func (be *b2Backend) List(ctx context.Context, t restic.FileType) <-chan string cur := &b2.Cursor{Prefix: prefix} for { - objs, c, err := be.bucket.ListCurrentObjects(ctx, 1000, cur) + objs, c, err := be.bucket.ListCurrentObjects(ctx, be.listMaxItems, cur) if err != nil && err != io.EOF { return } + debug.Log("returned %v items", len(objs)) for _, obj := range objs { // Skip objects returned that do not have the specified prefix. if !strings.HasPrefix(obj.Name(), prefix) {