2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-22 10:58:55 +00:00

Merge pull request #3905 from DRON-666/haspaths-linear

Reduce quadratic time complexity of `Snapshot.HasPaths`
This commit is contained in:
Michael Eischer 2022-08-30 20:35:56 +02:00 committed by GitHub
commit 6c69f08a7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 10 deletions

View File

@ -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

View File

@ -237,19 +237,14 @@ func (sn *Snapshot) HasTagList(l []TagList) bool {
return false 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. // HasPaths returns true if the snapshot has all of the paths.
func (sn *Snapshot) HasPaths(paths []string) bool { 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 { for _, path := range paths {
if !sn.hasPath(path) { if _, ok := m[path]; !ok {
return false return false
} }
} }