restic prune: Merge three loops over the index

There were three loops over the index in restic prune, to find
duplicates, to determine sizes (in pack.Size) and to generate packInfos.
These three are now one loop. This way, prune doesn't need to construct
a set of duplicate blobs, pack.Size doesn't need to contain special
logic for prune's use case (the onlyHdr argument) and pack.Size doesn't
need to construct a map only to have it immediately transformed into a
different map.

Some quick testing on a 160GiB local repo doesn't show running time or
memory use of restic prune --dry-run changing significantly.
This commit is contained in:
greatroar
2022-06-05 10:14:32 +02:00
parent b7c990871f
commit 8bdfcf779f
4 changed files with 42 additions and 59 deletions

View File

@@ -131,7 +131,7 @@ func (c *Checker) LoadIndex(ctx context.Context) (hints []error, errs []error) {
}
// compute pack size using index entries
c.packs = pack.Size(ctx, c.masterIndex, false)
c.packs = pack.Size(ctx, c.masterIndex)
debug.Log("checking for duplicate packs")
for packID := range c.packs {