From b5543cff5d84a5b2baa95ef98be7befbbc431033 Mon Sep 17 00:00:00 2001 From: Alexander Weiss Date: Sun, 14 Jun 2020 09:50:11 +0200 Subject: [PATCH] Loop over index files for 'list blobs' => reduces memory consumption a lot! --- changelog/unreleased/pull-2786 | 6 ++++++ cmd/restic/cmd_list.go | 20 ++++++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) create mode 100644 changelog/unreleased/pull-2786 diff --git a/changelog/unreleased/pull-2786 b/changelog/unreleased/pull-2786 new file mode 100644 index 000000000..ec0654cda --- /dev/null +++ b/changelog/unreleased/pull-2786 @@ -0,0 +1,6 @@ +Enhancement: Optimize `list blobs` command + +We've changed the implementation of `list blobs` which should be now a bit faster +and consume almost no memory even for large repositories. + +https://github.com/restic/restic/pull/2786 diff --git a/cmd/restic/cmd_list.go b/cmd/restic/cmd_list.go index 990ca6b9e..696db7642 100644 --- a/cmd/restic/cmd_list.go +++ b/cmd/restic/cmd_list.go @@ -2,7 +2,7 @@ package main import ( "github.com/restic/restic/internal/errors" - "github.com/restic/restic/internal/index" + "github.com/restic/restic/internal/repository" "github.com/restic/restic/internal/restic" "github.com/spf13/cobra" @@ -60,16 +60,16 @@ func runList(cmd *cobra.Command, opts GlobalOptions, args []string) error { case "locks": t = restic.LockFile case "blobs": - idx, err := index.Load(opts.ctx, repo, nil) - if err != nil { - return err - } - - for _, pack := range idx.Packs { - for _, entry := range pack.Entries { - Printf("%v %v\n", entry.Type, entry.ID) + return repo.List(opts.ctx, restic.IndexFile, func(id restic.ID, size int64) error { + idx, err := repository.LoadIndex(opts.ctx, repo, id) + if err != nil { + return err } - } + for blobs := range idx.Each(opts.ctx) { + Printf("%v %v\n", blobs.Type, blobs.ID) + } + return nil + }) return nil default: