From d0f1060df74d3c88ebc26c83924ae5e13ab6408b Mon Sep 17 00:00:00 2001 From: DRON-666 <64691982+DRON-666@users.noreply.github.com> Date: Tue, 30 Aug 2022 04:38:17 +0300 Subject: [PATCH 1/2] Fix quadratic time complexity of Snapshot.HasPaths --- internal/restic/snapshot.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/internal/restic/snapshot.go b/internal/restic/snapshot.go index 10c4f218e..9eb7ab3ab 100644 --- a/internal/restic/snapshot.go +++ b/internal/restic/snapshot.go @@ -237,19 +237,14 @@ func (sn *Snapshot) HasTagList(l []TagList) bool { return false } -func (sn *Snapshot) hasPath(path string) bool { - for _, snPath := range sn.Paths { - if path == snPath { - return true - } - } - return false -} - // HasPaths returns true if the snapshot has all of the paths. func (sn *Snapshot) HasPaths(paths []string) bool { + m := make(map[string]struct{}, len(sn.Paths)) + for _, snPath := range sn.Paths { + m[snPath] = struct{}{} + } for _, path := range paths { - if !sn.hasPath(path) { + if _, ok := m[path]; !ok { return false } } From 2a630c51c1f87838afaab115f3b68f0072f643ff Mon Sep 17 00:00:00 2001 From: DRON-666 <64691982+DRON-666@users.noreply.github.com> Date: Tue, 30 Aug 2022 04:52:24 +0300 Subject: [PATCH 2/2] Add changelog --- changelog/unreleased/pull-3905 | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 changelog/unreleased/pull-3905 diff --git a/changelog/unreleased/pull-3905 b/changelog/unreleased/pull-3905 new file mode 100644 index 000000000..f9d55da6e --- /dev/null +++ b/changelog/unreleased/pull-3905 @@ -0,0 +1,6 @@ +Enhancement: Improve speed of parent snapshot searching for `backup` command + +Backing up a large number of files using `--files-from-verbatim` or `--files-from-raw` +options could require a long time to find the parent snapshot. This has been improved. + +https://github.com/restic/restic/pull/3905