瀏覽代碼

Improvements Database

Marino Faggiana 7 年之前
父節點
當前提交
6b11a2a740

+ 1 - 1
iOSClient/Brand/Picker.plist

@@ -19,7 +19,7 @@
 	<key>CFBundleShortVersionString</key>
 	<key>CFBundleShortVersionString</key>
 	<string>2.17.4</string>
 	<string>2.17.4</string>
 	<key>CFBundleVersion</key>
 	<key>CFBundleVersion</key>
-	<string>00029</string>
+	<string>00030</string>
 	<key>NSAppTransportSecurity</key>
 	<key>NSAppTransportSecurity</key>
 	<dict>
 	<dict>
 		<key>NSAllowsArbitraryLoads</key>
 		<key>NSAllowsArbitraryLoads</key>

+ 1 - 1
iOSClient/Brand/PickerFileProvider.plist

@@ -19,7 +19,7 @@
 	<key>CFBundleShortVersionString</key>
 	<key>CFBundleShortVersionString</key>
 	<string>2.17.4</string>
 	<string>2.17.4</string>
 	<key>CFBundleVersion</key>
 	<key>CFBundleVersion</key>
-	<string>00029</string>
+	<string>00030</string>
 	<key>NSExtension</key>
 	<key>NSExtension</key>
 	<dict>
 	<dict>
 		<key>NSExtensionFileProviderDocumentGroup</key>
 		<key>NSExtensionFileProviderDocumentGroup</key>

+ 1 - 1
iOSClient/Brand/Share.plist

@@ -19,7 +19,7 @@
 	<key>CFBundleShortVersionString</key>
 	<key>CFBundleShortVersionString</key>
 	<string>2.17.4</string>
 	<string>2.17.4</string>
 	<key>CFBundleVersion</key>
 	<key>CFBundleVersion</key>
-	<string>00029</string>
+	<string>00030</string>
 	<key>NSAppTransportSecurity</key>
 	<key>NSAppTransportSecurity</key>
 	<dict>
 	<dict>
 		<key>NSAllowsArbitraryLoads</key>
 		<key>NSAllowsArbitraryLoads</key>

+ 1 - 1
iOSClient/Brand/iOSClient.plist

@@ -69,7 +69,7 @@
 		</dict>
 		</dict>
 	</array>
 	</array>
 	<key>CFBundleVersion</key>
 	<key>CFBundleVersion</key>
-	<string>00029</string>
+	<string>00030</string>
 	<key>Fabric</key>
 	<key>Fabric</key>
 	<dict>
 	<dict>
 		<key>APIKey</key>
 		<key>APIKey</key>

+ 4 - 0
iOSClient/Database/NCDatabase.swift

@@ -201,6 +201,10 @@ class tableMetadata: Object {
     override static func primaryKey() -> String {
     override static func primaryKey() -> String {
         return "fileID"
         return "fileID"
     }
     }
+    
+    override static func indexedProperties() -> [String] {
+        return ["directoryID"]
+    }
 }
 }
 
 
 class tablePhotoLibrary: Object {
 class tablePhotoLibrary: Object {

+ 12 - 25
iOSClient/Database/NCManageDatabase.swift

@@ -36,11 +36,11 @@ class NCManageDatabase: NSObject {
         let config = Realm.Configuration(
         let config = Realm.Configuration(
         
         
             fileURL: dirGroup?.appendingPathComponent("\(appDatabaseNextcloud)/\(k_databaseDefault)"),
             fileURL: dirGroup?.appendingPathComponent("\(appDatabaseNextcloud)/\(k_databaseDefault)"),
-            schemaVersion: 2,
+            schemaVersion: 3,
             
             
             migrationBlock: { migration, oldSchemaVersion in
             migrationBlock: { migration, oldSchemaVersion in
                 // We haven’t migrated anything yet, so oldSchemaVersion == 0
                 // We haven’t migrated anything yet, so oldSchemaVersion == 0
-                if (oldSchemaVersion < 2) {
+                if (oldSchemaVersion < 3) {
                     // Nothing to do!
                     // Nothing to do!
                     // Realm will automatically detect new properties and removed properties
                     // Realm will automatically detect new properties and removed properties
                     // And will update the schema on disk automatically
                     // And will update the schema on disk automatically
@@ -1786,32 +1786,19 @@ class NCManageDatabase: NSObject {
         
         
         var recordsPhotosAutoUpload = [tableMetadata]()
         var recordsPhotosAutoUpload = [tableMetadata]()
         
         
-        let results = self.getTablesDirectory(predicate: NSPredicate(format: "account = %@ AND serverUrl BEGINSWITH %@", tableAccount.account, serverUrl), sorted: "serverUrl", ascending: true)
-        
-        if results != nil {
-            
-            // Prepare Predicate
-            var directoriesID: String = "IN {"
-            for directory in results! {
-                directoriesID = directoriesID + "'\(directory.directoryID)',"
-            }
-            directoriesID = String(directoriesID.characters.dropLast(1))
-            directoriesID = directoriesID + "}"
-            
-            let predicateStr = String(format: "account = '%@' AND session = '' AND type = 'file' AND (typeFile = '%@' OR typeFile = '%@') AND directoryID %@", tableAccount.account, k_metadataTypeFile_image, k_metadataTypeFile_video, directoriesID)
-            
-            // Query
-            let metadatas = realm.objects(tableMetadata.self).filter(NSPredicate(format: predicateStr)).sorted(byKeyPath: "date", ascending: false)
+        let results = realm.objects(tableDirectory.self).filter(NSPredicate(format: "account = %@ AND serverUrl BEGINSWITH %@", tableAccount.account, serverUrl)).sorted(byKeyPath: "serverUrl", ascending: true)
+        let directoriesID = Array(results.map { $0.directoryID })
 
 
-            // Convert results in unmanaged
-            for metadata in metadatas {
-                recordsPhotosAutoUpload.append(tableMetadata.init(value: metadata))
-            }
+        let predicate = NSPredicate(format: "account = %@ AND session = '' AND type = 'file' AND (typeFile = %@ OR typeFile = %@) AND directoryID IN %@", tableAccount.account, k_metadataTypeFile_image, k_metadataTypeFile_video, directoriesID)
+            
+        let metadatas = realm.objects(tableMetadata.self).filter(predicate).sorted(byKeyPath: "date", ascending: false)
             
             
-            return Array(recordsPhotosAutoUpload)
+        // Convert results in unmanaged
+        for metadata in metadatas {
+            recordsPhotosAutoUpload.append(tableMetadata.init(value: metadata))
         }
         }
-        
-        return nil
+            
+        return Array(recordsPhotosAutoUpload)
     }
     }
     
     
     func convertMetadataToUnmanagedMetadata(_ metadatas: Results<tableMetadata>) -> [tableMetadata]? {
     func convertMetadataToUnmanagedMetadata(_ metadatas: Results<tableMetadata>) -> [tableMetadata]? {