Skip to content

Commit

Permalink
Minor performance improvement on iCloud file progress monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
amosavian committed May 3, 2018
1 parent 1f4fef7 commit c1a5bae
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions Sources/CloudFileProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,23 @@ open class CloudFileProvider: LocalFileProvider, FileProviderSharing {
}

fileprivate func monitorFile(path: String, operation: FileOperationType, progress: Progress?) {
var isDownloadingOperation: Bool
let isUploadingOperation: Bool
switch operation {
case .copy(_, destination: let dest) where dest.hasPrefix("file://"), .move(_, destination: let dest) where dest.hasPrefix("file://"):
fallthrough
case .fetch:
isDownloadingOperation = true
isUploadingOperation = false
case .copy(source: let source, _) where source.hasPrefix("file://"), .move(source: let source, _) where source.hasPrefix("file://"):
fallthrough
case .modify, .create:
isDownloadingOperation = false
isUploadingOperation = true
default:
return
}

let pathURL = self.url(of: path).standardizedFileURL
let query = NSMetadataQuery()
query.predicate = NSPredicate(format: "(%K LIKE[CD] %@)", NSMetadataItemPathKey, pathURL.path)
Expand All @@ -594,22 +611,6 @@ open class CloudFileProvider: LocalFileProvider, FileProviderSharing {
NSMetadataItemFSSizeKey]
query.searchScopes = [self.scope.rawValue]

var isDownloadingOperation = false
var isUploadingOperation = false

switch operation {
case .fetch:
isDownloadingOperation = true
case .modify, .create:
isUploadingOperation = true
case .copy(_, destination: let dest) where dest.hasPrefix("file://"), .move(_, destination: let dest) where dest.hasPrefix("file://"):
isDownloadingOperation = true
case .copy(source: let source, _) where source.hasPrefix("file://"), .move(source: let source, _) where source.hasPrefix("file://"):
isDownloadingOperation = true
default:
break
}

var observer: NSObjectProtocol?
observer = NotificationCenter.default.addObserver(forName: .NSMetadataQueryDidUpdate, object: query, queue: .main) { [weak self] (notification) in
guard let items = notification.userInfo?[NSMetadataQueryUpdateChangedItemsKey] as? NSArray,
Expand Down

0 comments on commit c1a5bae

Please sign in to comment.