From 47243176fa460cae6209bc446b580d4333992a4b Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sun, 7 Nov 2021 21:26:05 +0100 Subject: [PATCH] diff: list snapshots only once --- cmd/restic/cmd_diff.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/cmd/restic/cmd_diff.go b/cmd/restic/cmd_diff.go index ae76e4071..8099bf296 100644 --- a/cmd/restic/cmd_diff.go +++ b/cmd/restic/cmd_diff.go @@ -7,9 +7,9 @@ import ( "reflect" "sort" + "github.com/restic/restic/internal/backend" "github.com/restic/restic/internal/debug" "github.com/restic/restic/internal/errors" - "github.com/restic/restic/internal/repository" "github.com/restic/restic/internal/restic" "github.com/spf13/cobra" ) @@ -53,8 +53,8 @@ func init() { f.BoolVar(&diffOptions.ShowMetadata, "metadata", false, "print changes in metadata") } -func loadSnapshot(ctx context.Context, repo *repository.Repository, desc string) (*restic.Snapshot, error) { - id, err := restic.FindSnapshot(ctx, repo.Backend(), desc) +func loadSnapshot(ctx context.Context, be restic.Lister, repo restic.Repository, desc string) (*restic.Snapshot, error) { + id, err := restic.FindSnapshot(ctx, be, desc) if err != nil { return nil, errors.Fatal(err.Error()) } @@ -342,12 +342,17 @@ func runDiff(opts DiffOptions, gopts GlobalOptions, args []string) error { } } - sn1, err := loadSnapshot(ctx, repo, args[0]) + // cache snapshots listing + be, err := backend.MemorizeList(ctx, repo.Backend(), restic.SnapshotFile) + if err != nil { + return err + } + sn1, err := loadSnapshot(ctx, be, repo, args[0]) if err != nil { return err } - sn2, err := loadSnapshot(ctx, repo, args[1]) + sn2, err := loadSnapshot(ctx, be, repo, args[1]) if err != nil { return err }