diff --git a/Duplicati/Library/Main/Operation/CompactHandler.cs b/Duplicati/Library/Main/Operation/CompactHandler.cs index beea6d391..443937f20 100644 --- a/Duplicati/Library/Main/Operation/CompactHandler.cs +++ b/Duplicati/Library/Main/Operation/CompactHandler.cs @@ -128,9 +128,16 @@ namespace Duplicati.Library.Main.Operation var downloadedVolumes = new List>(); //We start by deleting unused volumes to save space before uploading new stuff - var fullyDeleteable = (from v in remoteList - where report.DeleteableVolumes.Contains(v.Name) - select (IRemoteVolume)v).ToList(); + List fullyDeleteable = []; + if (report.DeleteableVolumes.Any()) + { + var deleteableVolumesAsHashSet = new HashSet(report.DeleteableVolumes); + fullyDeleteable = + remoteList + .Where(n => deleteableVolumesAsHashSet.Contains(n.Name)) + .Cast() + .ToList(); + } deletedVolumes.AddRange(DoDelete(db, backend, fullyDeleteable, ref transaction)); // This list is used to pick up unused volumes, @@ -141,9 +148,16 @@ namespace Duplicati.Library.Main.Operation if (report.ShouldCompact) { newvolindex?.StartVolume(newvol.RemoteFilename); - var volumesToDownload = (from v in remoteList - where report.CompactableVolumes.Contains(v.Name) - select (IRemoteVolume)v).ToList(); + List volumesToDownload = []; + if (report.CompactableVolumes.Any()) + { + var compactableVolumesAsHashSet = new HashSet(report.CompactableVolumes); + volumesToDownload = + remoteList + .Where(n => compactableVolumesAsHashSet.Contains(n.Name)) + .Cast() + .ToList(); + } using (var q = db.CreateBlockQueryHelper(transaction)) {