Skip to content

Commit c2b7285

Browse files
committed
Core performance refactoring
1 parent 5f8d853 commit c2b7285

File tree

6 files changed

+8
-8
lines changed

6 files changed

+8
-8
lines changed

iTorrent/Screens/TorrentDetails/TorrentDetailsViewModel.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class TorrentDetailsViewModel: BaseViewModelWith<TorrentHandle> {
2525

2626
override func prepare(with model: TorrentHandle) {
2727
torrentHandle = model
28-
title = model.name
28+
title = torrentHandle.snapshot.name
2929

3030
dataUpdate()
3131
reload()
@@ -246,7 +246,7 @@ private extension TorrentDetailsViewModel {
246246
leechersModel.detail = "\(torrentHandle.snapshot.numberOfLeechers)(\(torrentHandle.snapshot.numberOfTotalLeechers))"
247247

248248
downloadPath2Model.detail = torrentHandle.snapshot.downloadPath?.path() ?? ""
249-
downloadPathModel.value = torrentHandle.snapshot.storage.name
249+
downloadPathModel.value = torrentHandle.storage.name
250250

251251
filesModel.isEnabled = torrentHandle.snapshot.friendlyState != .storageError && torrentHandle.snapshot.hasMetadata
252252
}

iTorrent/Screens/TorrentList/TorrentListViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ private extension TorrentListViewController {
269269
collectionView.$selectedIndexPaths.uiSink { [unowned self] indexPaths in
270270
let torrentHandles = indexPaths.compactMap { (viewModel.sections[$0.section].items[$0.item] as? TorrentListItemViewModel)?.torrentHandle }
271271

272-
playButton.isEnabled = torrentHandles.contains(where: { $0.isPaused })
273-
pauseButton.isEnabled = torrentHandles.contains(where: { !$0.isPaused })
272+
playButton.isEnabled = torrentHandles.contains(where: { $0.snapshot.isPaused })
273+
pauseButton.isEnabled = torrentHandles.contains(where: { !$0.snapshot.isPaused })
274274
rehashButton.isEnabled = !torrentHandles.isEmpty
275275
deleteButton.isEnabled = !torrentHandles.isEmpty
276276
}

iTorrent/Screens/TorrentList/TorrentListViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ private extension TorrentListViewModel {
227227

228228
private extension Array where Element == TorrentHandle {
229229
func sorted(by type: TorrentListViewModel.Sort, reverced: Bool) -> [Element] {
230-
let res = filter(\.isValid).sorted { first, second in
230+
let res = filter(\.snapshot.isValid).sorted { first, second in
231231
switch type {
232232
case .alphabetically:
233233
return first.snapshot.name.localizedCaseInsensitiveCompare(second.snapshot.name) == .orderedAscending

iTorrent/Services/TorrentService/Extensions/TorrentHandle+Extension.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ extension TorrentHandle.State {
121121
}
122122

123123
// MARK: - Storage
124-
extension TorrentHandle.Snapshot {
124+
extension TorrentHandle {
125125
var storage: StorageModel? {
126126
guard let storageUUID else { return nil }
127127
return TorrentService.shared.storages[storageUUID]

iTorrent/Services/TorrentService/TorrentService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ extension TorrentService {
8181
func refreshStorage(_ storage: StorageModel) -> Bool {
8282
guard storage.resolveSequrityScopes() else { return false }
8383

84-
let handles = torrents.values.filter { $0.snapshot.storageUUID == storage.uuid }
84+
let handles = torrents.values.filter { $0.storageUUID == storage.uuid }
8585
handles.forEach { $0.reload() }
8686
return true
8787
}

0 commit comments

Comments
 (0)