2
2
mirror of https://github.com/octoleo/restic.git synced 2024-06-02 17:10:49 +00:00

repository: Don't sort one element pack lists

When loading a blob, restic first looks up pack files containing the
blob. To avoid unnecessary work an already cached pack file is preferred.
However, if there is only a single pack file to choose from (which is
the normal case) sorting the one-element list won't change anything.
Therefore avoid the unnecessary cache check in that case.
This commit is contained in:
Michael Eischer 2019-07-06 17:42:29 +02:00
parent a307797c11
commit b46cc6d57e

View File

@ -111,6 +111,11 @@ func (r *Repository) sortCachedPacks(blobs []restic.PackedBlob) []restic.PackedB
return blobs
}
// no need to sort a list with one element
if len(blobs) == 1 {
return blobs
}
cached := make([]restic.PackedBlob, 0, len(blobs)/2)
noncached := make([]restic.PackedBlob, 0, len(blobs)/2)