Browse Source

fix search

Marino Faggiana 7 years ago
parent
commit
5fd73395a9
2 changed files with 11 additions and 12 deletions
  1. 7 3
      iOSClient/FileSystem/NCManageDatabase.swift
  2. 4 9
      iOSClient/Main/CCMain.m

+ 7 - 3
iOSClient/FileSystem/NCManageDatabase.swift

@@ -1150,12 +1150,16 @@ class NCManageDatabase: NSObject {
         let cameraFolderPath = self.getAccountCameraUploadFolderPath(activeUrl)
         let direcory = CCCoreData.getServerUrl(fromDirectoryID: metadata.directoryID, activeAccount: metadata.account)
         
-        let metadataWithIcon = CCUtility.insertTypeFileIconName(metadata, directory: direcory, cameraFolderName: cameraFolderName, cameraFolderPath: cameraFolderPath)
-        
         let realm = try! Realm()
         
         try! realm.write {
-            realm.add(metadataWithIcon!, update: true)
+            
+            if (metadata.realm == nil) {
+                let metadataWithIcon = CCUtility.insertTypeFileIconName(metadata, directory: direcory, cameraFolderName: cameraFolderName, cameraFolderPath: cameraFolderPath)
+                realm.add(metadataWithIcon!, update: true)
+            } else {
+                realm.add(metadata, update: true)
+            }
         }
     }
     

+ 4 - 9
iOSClient/Main/CCMain.m

@@ -1847,12 +1847,6 @@
     
     for (tableMetadata *metadata in metadatas) {
         
-        // Delete Record only in Search Mode
-        if (_isSearchMode) {
-            
-            [[NCManageDatabase sharedInstance] deleteMetadata:[NSPredicate predicateWithFormat:@"etag = %@ AND session = ''", metadata.etag]];
-        }
-        
         // type of file
         NSInteger typeFilename = [CCUtility getTypeFileName:metadata.fileName];
         
@@ -1915,13 +1909,14 @@
             if (metadataDB.session && [metadataDB.session containsString:@"download"])
                 continue;
         }
-
-        // end test, insert in CoreData
+        
+        // end test, insert in Database
         [[NCManageDatabase sharedInstance] addMetadata:metadata activeUrl:app.activeUrl];
     }
     
     // read plist
-    [self downloadPlist:metadataNet.directoryID serverUrl:metadataNet.serverUrl];
+    if (!_isSearchMode)
+        [self downloadPlist:metadataNet.directoryID serverUrl:metadataNet.serverUrl];
     
     // File is changed ??
     if (!_isSearchMode)