serve restic: use ListR (--fast-list) if available

For Restic's use case, --fast-list will use less transactions and
calling ListR directly means we can avoid the usual memory overhead.
This commit is contained in:
Nick Craig-Wood 2018-03-18 14:26:10 +00:00
parent 82e835d6fc
commit 1313b529ff

View File

@ -405,14 +405,25 @@ func (s *server) listObjects(w http.ResponseWriter, r *http.Request, remote stri
// make sure an empty list is returned, and not a 'nil' value
ls := listItems{}
err := walk.Walk(s.f, remote, true, -1, func(path string, entries fs.DirEntries, err error) error {
if err == nil {
// if remote supports ListR use that directly, otherwise use recursive Walk
var err error
if ListR := s.f.Features().ListR; ListR != nil {
err = ListR(remote, func(entries fs.DirEntries) error {
for _, entry := range entries {
ls.add(entry)
}
}
return err
})
return nil
})
} else {
err = walk.Walk(s.f, remote, true, -1, func(path string, entries fs.DirEntries, err error) error {
if err == nil {
for _, entry := range entries {
ls.add(entry)
}
}
return err
})
}
if err != nil {
_, err = fserrors.Cause(err)