]> dgit.raspbian.org Git - nextcloud-desktop.git/commitdiff
Don't unnecessarily fetch item metadata when fetching contents
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Mon, 20 Feb 2023 12:42:28 +0000 (13:42 +0100)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Fri, 12 May 2023 05:21:19 +0000 (13:21 +0800)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderExtension.swift

index 8ec872de8558ddc1ec96a3fbd9289375e8024dd7..c326685de305da0f800e967515ea095805f97b04 100644 (file)
@@ -133,7 +133,11 @@ class FileProviderExtension: NSObject, NSFileProviderReplicatedExtension, NKComm
         do {
             let fileNameLocalPath = try localPathForNCFile(ocId: metadata.ocId, fileNameView: metadata.fileNameView)
 
-            _ = dbManager.setStatusForItemMetadata(metadata, status: NextcloudItemMetadataTable.Status.downloading)
+            guard let updatedMetadata = dbManager.setStatusForItemMetadata(metadata, status: NextcloudItemMetadataTable.Status.downloading) else {
+                NSLog("Could not acquire updated metadata of item with identifier: %@", itemIdentifier.rawValue)
+                completionHandler(nil, nil, NSFileProviderError(.noSuchItem))
+                return Progress()
+            }
 
             self.ncKit.download(serverUrlFileName: serverUrlFileName,
                                 fileNameLocalPath: fileNameLocalPath.path,
@@ -146,11 +150,6 @@ class FileProviderExtension: NSObject, NSFileProviderReplicatedExtension, NKComm
 
             }) { _, etag, date, _, _, _, error in
                 self.outstandingSessionTasks.removeValue(forKey: serverUrlFileName)
-                guard let updatedMetadata = dbManager.itemMetadataFromOcId(ocId) else {
-                    NSLog("Could not acquire updated metadata of item with identifier: %@", itemIdentifier.rawValue)
-                    completionHandler(nil, nil, NSFileProviderError(.noSuchItem))
-                    return
-                }
 
                 if error == .success {
                     NSLog("Acquired contents of item with identifier: %@ and filename: %@", itemIdentifier.rawValue, updatedMetadata.fileName)
@@ -188,7 +187,7 @@ class FileProviderExtension: NSObject, NSFileProviderReplicatedExtension, NKComm
     
     func createItem(basedOn itemTemplate: NSFileProviderItem, fields: NSFileProviderItemFields, contents url: URL?, options: NSFileProviderCreateItemOptions = [], request: NSFileProviderRequest, completionHandler: @escaping (NSFileProviderItem?, NSFileProviderItemFields, Bool, Error?) -> Void) -> Progress {
         // TODO: a new item was created on disk, process the item's creation
-        
+
         completionHandler(itemTemplate, [], false, nil)
         return Progress()
     }