Skip to content

Commit

Permalink
Core performance refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
XITRIX committed Nov 23, 2024
1 parent 5f8d853 commit c2b7285
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions iTorrent/Screens/TorrentDetails/TorrentDetailsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class TorrentDetailsViewModel: BaseViewModelWith<TorrentHandle> {

override func prepare(with model: TorrentHandle) {
torrentHandle = model
title = model.name
title = torrentHandle.snapshot.name

dataUpdate()
reload()
Expand Down Expand Up @@ -246,7 +246,7 @@ private extension TorrentDetailsViewModel {
leechersModel.detail = "\(torrentHandle.snapshot.numberOfLeechers)(\(torrentHandle.snapshot.numberOfTotalLeechers))"

downloadPath2Model.detail = torrentHandle.snapshot.downloadPath?.path() ?? ""
downloadPathModel.value = torrentHandle.snapshot.storage.name
downloadPathModel.value = torrentHandle.storage.name

filesModel.isEnabled = torrentHandle.snapshot.friendlyState != .storageError && torrentHandle.snapshot.hasMetadata
}
Expand Down
4 changes: 2 additions & 2 deletions iTorrent/Screens/TorrentList/TorrentListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ private extension TorrentListViewController {
collectionView.$selectedIndexPaths.uiSink { [unowned self] indexPaths in
let torrentHandles = indexPaths.compactMap { (viewModel.sections[$0.section].items[$0.item] as? TorrentListItemViewModel)?.torrentHandle }

playButton.isEnabled = torrentHandles.contains(where: { $0.isPaused })
pauseButton.isEnabled = torrentHandles.contains(where: { !$0.isPaused })
playButton.isEnabled = torrentHandles.contains(where: { $0.snapshot.isPaused })
pauseButton.isEnabled = torrentHandles.contains(where: { !$0.snapshot.isPaused })
rehashButton.isEnabled = !torrentHandles.isEmpty
deleteButton.isEnabled = !torrentHandles.isEmpty
}
Expand Down
2 changes: 1 addition & 1 deletion iTorrent/Screens/TorrentList/TorrentListViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ private extension TorrentListViewModel {

private extension Array where Element == TorrentHandle {
func sorted(by type: TorrentListViewModel.Sort, reverced: Bool) -> [Element] {
let res = filter(\.isValid).sorted { first, second in
let res = filter(\.snapshot.isValid).sorted { first, second in
switch type {
case .alphabetically:
return first.snapshot.name.localizedCaseInsensitiveCompare(second.snapshot.name) == .orderedAscending
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ extension TorrentHandle.State {
}

// MARK: - Storage
extension TorrentHandle.Snapshot {
extension TorrentHandle {
var storage: StorageModel? {
guard let storageUUID else { return nil }
return TorrentService.shared.storages[storageUUID]
Expand Down
2 changes: 1 addition & 1 deletion iTorrent/Services/TorrentService/TorrentService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ extension TorrentService {
func refreshStorage(_ storage: StorageModel) -> Bool {
guard storage.resolveSequrityScopes() else { return false }

let handles = torrents.values.filter { $0.snapshot.storageUUID == storage.uuid }
let handles = torrents.values.filter { $0.storageUUID == storage.uuid }
handles.forEach { $0.reload() }
return true
}
Expand Down

0 comments on commit c2b7285

Please sign in to comment.