Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.
Swift cache-cleanercleanerclideveloper-toolsdisk-cleanupdisk-spaceduplicate-finderhomebrewliquid-glassmac-cleanermacosmacos-appmacos-golden-gatemacos-tahoemacos-tweaksswiftswiftuiterminal-themesuninstalluninstaller
Count a duplicate group's staying copies once a draw, not once a row
Țugui Dragoșde5cd16fc007
diff --git a/Packages/PeelCore/Sources/PeelCore/Duplicates/Duplicates.swift b/Packages/PeelCore/Sources/PeelCore/Duplicates/Duplicates.swiftindex cb3f5a48..f180292f 100644--- a/Packages/PeelCore/Sources/PeelCore/Duplicates/Duplicates.swift+++ b/Packages/PeelCore/Sources/PeelCore/Duplicates/Duplicates.swift@@ -194,13 +194,28 @@ public struct DuplicateScan: Sendable {/// Whether the copy at `url` may be selected or deselected, given the `selected` copies of its group: one copy of/// every group always stays, so the last one not selected cannot be.public static func canChange(_ url: URL, among copies: [URL], selected: Set<URL>) -> Bool {- selected.contains(url) || copies.count { !selected.contains($0) } > 1+ canChange(url, staying: copies.count { !selected.contains($0) }, selected: selected)+ }++ /// `canChange(_:among:selected:)` with `staying`, the copies of the group not selected, counted once for the+ /// whole group: counted again for each copy, a group of thousands costs millions of lookups each time its page is+ /// drawn.+ public static func canChange(_ url: URL, staying: Int, selected: Set<URL>) -> Bool {+ selected.contains(url) || staying > 1}/// `canChange(_:among:selected:)` for a copy of `group`: one held back can never be selected, and it counts as a/// copy that stays for the others.public static func canChange(_ file: DuplicateFile, in group: DuplicateGroup, selected: Set<URL>) -> Bool {- file.heldBack == nil && canChange(file.url, among: group.files.map(\.url), selected: selected)+ canChange(file, staying: staying(in: group, selected: selected), selected: selected)+ }++ public static func canChange(_ file: DuplicateFile, staying: Int, selected: Set<URL>) -> Bool {+ file.heldBack == nil && canChange(file.url, staying: staying, selected: selected)+ }++ public static func staying(in group: DuplicateGroup, selected: Set<URL>) -> Int {+ group.files.count { !selected.contains($0.url) }}private static func keepingOne(of groups: [[URL]], _ selection: Set<URL>) -> Set<URL> {diff --git a/Peel/Model/DuplicateLibrary.swift b/Peel/Model/DuplicateLibrary.swiftindex 0b122018..701a3eb9 100644--- a/Peel/Model/DuplicateLibrary.swift+++ b/Peel/Model/DuplicateLibrary.swift@@ -209,6 +209,15 @@ final class DuplicateLibrary {DuplicateScan.canChange(file, in: group, selected: selectedURLs)}+ /// How many copies of `group` are not selected, which a page counts once and gives each copy's checkbox.+ func staying(in group: DuplicateGroup) -> Int {+ DuplicateScan.staying(in: group, selected: selectedURLs)+ }++ func canChange(_ file: DuplicateFile, staying: Int) -> Bool {+ DuplicateScan.canChange(file, staying: staying, selected: selectedURLs)+ }+/// Changes nothing that would leave the group with no copy.func setSelected(_ isSelected: Bool, _ file: DuplicateFile, in group: DuplicateGroup) {guard canChange(file, in: group) else { return }@@ -233,6 +242,15 @@ final class DuplicateLibrary {DuplicateScan.canChange(folder.url, among: group.folders.map(\.url), selected: selectedFolders)}+ /// How many copies of `group` are not selected, which a page counts once and gives each copy's checkbox.+ func staying(in group: DuplicateFolderGroup) -> Int {+ group.folders.count { !selectedFolders.contains($0.url) }+ }++ func canChange(_ folder: DuplicateFolder, staying: Int) -> Bool {+ DuplicateScan.canChange(folder.url, staying: staying, selected: selectedFolders)+ }+/// Changes nothing that would leave the group with no copy.func setSelected(_ isSelected: Bool, _ folder: DuplicateFolder, in group: DuplicateFolderGroup) {guard canChange(folder, in: group) else { return }diff --git a/Peel/Views/Duplicates/DuplicateFolderGroupView.swift b/Peel/Views/Duplicates/DuplicateFolderGroupView.swiftindex 0bcf977c..ad438f43 100644--- a/Peel/Views/Duplicates/DuplicateFolderGroupView.swift+++ b/Peel/Views/Duplicates/DuplicateFolderGroupView.swift@@ -12,13 +12,14 @@ struct DuplicateFolderGroupView: View {RemovalsHeldBanner()Section {+ let staying = duplicates.staying(in: group)ForEach(Array(group.folders.enumerated()), id: \.element.id) { index, folder inDuplicateFolderRow(duplicates: duplicates,folder: folder,group: group,isSelected: duplicates.isSelected(folder),- canChangeSelection: duplicates.canChange(folder, in: group),+ canChangeSelection: duplicates.canChange(folder, staying: staying),isFirst: index == 0)}diff --git a/Peel/Views/Duplicates/DuplicateGroupView.swift b/Peel/Views/Duplicates/DuplicateGroupView.swiftindex dc55b040..a74e1035 100644--- a/Peel/Views/Duplicates/DuplicateGroupView.swift+++ b/Peel/Views/Duplicates/DuplicateGroupView.swift@@ -14,6 +14,7 @@ struct DuplicateGroupView: View {RemovalsHeldBanner()Section {+ let staying = duplicates.staying(in: group)ForEach(Array(group.files.enumerated()), id: \.element.id) { index, file inDuplicateFileRow(duplicates: duplicates,@@ -21,7 +22,7 @@ struct DuplicateGroupView: View {file: file,group: group,isSelected: duplicates.isSelected(file),- canChangeSelection: duplicates.canChange(file, in: group),+ canChangeSelection: duplicates.canChange(file, staying: staying),isFirst: index == 0)}