Skip to content

Commit 44598f8

Browse files
feat: cache content of different tabs (#3884)
Signed-off-by: Marino Faggiana <marino.faggiana@nextcloud.com>
1 parent 35bd87b commit 44598f8

File tree

11 files changed

+126
-150
lines changed

11 files changed

+126
-150
lines changed

Nextcloud.xcodeproj/project.pbxproj

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@
304304
F7327E322B73A86700A462C7 /* NCNetworking+WebDAV.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7327E2F2B73A86700A462C7 /* NCNetworking+WebDAV.swift */; };
305305
F7327E352B73AEDE00A462C7 /* NCNetworking+LivePhoto.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7327E342B73AEDE00A462C7 /* NCNetworking+LivePhoto.swift */; };
306306
F7327E3B2B73B8D600A462C7 /* Array+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7AC1CAF28AB94490032D99F /* Array+Extension.swift */; };
307-
F7327E3D2B73B92800A462C7 /* NCNetworking+Synchronization.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7327E3C2B73B92800A462C7 /* NCNetworking+Synchronization.swift */; };
308307
F732D23327CF8AED000B0F1B /* NCPlayerToolBar.xib in Resources */ = {isa = PBXBuildFile; fileRef = F732D23227CF8AED000B0F1B /* NCPlayerToolBar.xib */; };
309308
F733598125C1C188002ABA72 /* NCAskAuthorization.swift in Sources */ = {isa = PBXBuildFile; fileRef = F733598025C1C188002ABA72 /* NCAskAuthorization.swift */; };
310309
F7346E1628B0EF5C006CE2D2 /* Widget.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7346E1528B0EF5C006CE2D2 /* Widget.swift */; };
@@ -397,7 +396,6 @@
397396
F752BA052E58C05200616A26 /* Maintenance.swift in Sources */ = {isa = PBXBuildFile; fileRef = F752BA042E58C05200616A26 /* Maintenance.swift */; };
398397
F75379222AE2ADA100C0250E /* JGProgressHUD in Frameworks */ = {isa = PBXBuildFile; productRef = F75379212AE2ADA100C0250E /* JGProgressHUD */; };
399398
F753BA93281FD8020015BFB6 /* EasyTipView in Frameworks */ = {isa = PBXBuildFile; productRef = F753BA92281FD8020015BFB6 /* EasyTipView */; };
400-
F753DBDF2E5D99C300A1AF91 /* NCFiles+SyncMetadata.swift in Sources */ = {isa = PBXBuildFile; fileRef = F753DBDE2E5D99B700A1AF91 /* NCFiles+SyncMetadata.swift */; };
401399
F755BD9B20594AC7008C5FBB /* NCService.swift in Sources */ = {isa = PBXBuildFile; fileRef = F755BD9A20594AC7008C5FBB /* NCService.swift */; };
402400
F755CB402B8CB13C00CE27E9 /* NCMediaLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = F755CB3F2B8CB13C00CE27E9 /* NCMediaLayout.swift */; };
403401
F757CC8229E7F88B00F31428 /* NCManageDatabase+Groupfolders.swift in Sources */ = {isa = PBXBuildFile; fileRef = F757CC8129E7F88B00F31428 /* NCManageDatabase+Groupfolders.swift */; };
@@ -755,6 +753,7 @@
755753
F7CBC1242BAC8B0000EC1D55 /* NCSectionFirstHeaderEmptyData.xib in Resources */ = {isa = PBXBuildFile; fileRef = F7CBC1212BAC8B0000EC1D55 /* NCSectionFirstHeaderEmptyData.xib */; };
756754
F7CBC1252BAC8B0000EC1D55 /* NCSectionFirstHeaderEmptyData.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7CBC1222BAC8B0000EC1D55 /* NCSectionFirstHeaderEmptyData.swift */; };
757755
F7CBC1262BAC8B0000EC1D55 /* NCSectionFirstHeaderEmptyData.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7CBC1222BAC8B0000EC1D55 /* NCSectionFirstHeaderEmptyData.swift */; };
756+
F7CCAB512ECF316700F8E68B /* NCCollectionViewCommon+SyncMetadata.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7CCAB502ECF315F00F8E68B /* NCCollectionViewCommon+SyncMetadata.swift */; };
758757
F7CEE6002BA9A5C9003EFD89 /* NCTrashGridCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = F7CEE5FE2BA9A5C9003EFD89 /* NCTrashGridCell.xib */; };
759758
F7CEE6012BA9A5C9003EFD89 /* NCTrashGridCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7CEE5FF2BA9A5C9003EFD89 /* NCTrashGridCell.swift */; };
760759
F7CF06802E0FF3990063AD04 /* NCAppStateManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7CF067A2E0FF38F0063AD04 /* NCAppStateManager.swift */; };
@@ -1343,7 +1342,6 @@
13431342
F7327E1F2B73A42F00A462C7 /* NCNetworking+Download.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCNetworking+Download.swift"; sourceTree = "<group>"; };
13441343
F7327E2F2B73A86700A462C7 /* NCNetworking+WebDAV.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCNetworking+WebDAV.swift"; sourceTree = "<group>"; };
13451344
F7327E342B73AEDE00A462C7 /* NCNetworking+LivePhoto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCNetworking+LivePhoto.swift"; sourceTree = "<group>"; };
1346-
F7327E3C2B73B92800A462C7 /* NCNetworking+Synchronization.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCNetworking+Synchronization.swift"; sourceTree = "<group>"; };
13471345
F732D23227CF8AED000B0F1B /* NCPlayerToolBar.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NCPlayerToolBar.xib; sourceTree = "<group>"; };
13481346
F733598025C1C188002ABA72 /* NCAskAuthorization.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCAskAuthorization.swift; sourceTree = "<group>"; };
13491347
F7346E1028B0EF5B006CE2D2 /* Widget.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = Widget.appex; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -1386,7 +1384,6 @@
13861384
F753701822723D620041C76C /* gl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = gl; path = gl.lproj/Localizable.strings; sourceTree = "<group>"; };
13871385
F753701922723E0D0041C76C /* ca */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ca; path = ca.lproj/Localizable.strings; sourceTree = "<group>"; };
13881386
F753701A22723EC80041C76C /* da */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = da; path = da.lproj/Localizable.strings; sourceTree = "<group>"; };
1389-
F753DBDE2E5D99B700A1AF91 /* NCFiles+SyncMetadata.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCFiles+SyncMetadata.swift"; sourceTree = "<group>"; };
13901387
F755BD9A20594AC7008C5FBB /* NCService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCService.swift; sourceTree = "<group>"; };
13911388
F755CB3F2B8CB13C00CE27E9 /* NCMediaLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCMediaLayout.swift; sourceTree = "<group>"; };
13921389
F757CC8129E7F88B00F31428 /* NCManageDatabase+Groupfolders.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NCManageDatabase+Groupfolders.swift"; sourceTree = "<group>"; };
@@ -1685,6 +1682,7 @@
16851682
F7CBC1212BAC8B0000EC1D55 /* NCSectionFirstHeaderEmptyData.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NCSectionFirstHeaderEmptyData.xib; sourceTree = "<group>"; };
16861683
F7CBC1222BAC8B0000EC1D55 /* NCSectionFirstHeaderEmptyData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCSectionFirstHeaderEmptyData.swift; sourceTree = "<group>"; };
16871684
F7CC04E61F5AD50D00378CEF /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/Localizable.strings; sourceTree = "<group>"; };
1685+
F7CCAB502ECF315F00F8E68B /* NCCollectionViewCommon+SyncMetadata.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCCollectionViewCommon+SyncMetadata.swift"; sourceTree = "<group>"; };
16881686
F7CE8AFA1DC1F8D8009CAE48 /* Nextcloud.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Nextcloud.app; sourceTree = BUILT_PRODUCTS_DIR; };
16891687
F7CE8AFB1DC1F8D8009CAE48 /* Share.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = Share.appex; sourceTree = BUILT_PRODUCTS_DIR; };
16901688
F7CEE5FE2BA9A5C9003EFD89 /* NCTrashGridCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NCTrashGridCell.xib; sourceTree = "<group>"; };
@@ -2384,7 +2382,6 @@
23842382
F7327E342B73AEDE00A462C7 /* NCNetworking+LivePhoto.swift */,
23852383
F7F3E58A2D3BB65000A32B14 /* NCNetworking+Recommendations.swift */,
23862384
F7411C532D7B26C600F57358 /* NCNetworking+ServerError.swift */,
2387-
F7327E3C2B73B92800A462C7 /* NCNetworking+Synchronization.swift */,
23882385
F74230F22C79B57200CA1ACA /* NCNetworking+Task.swift */,
23892386
F785129A2D79899E0087DDD0 /* NCNetworking+TermsOfService.swift */,
23902387
F71916102E2901E800E13E96 /* NCNetworking+Upload.swift */,
@@ -2455,6 +2452,7 @@
24552452
F7D890742BD25C570050B8A6 /* NCCollectionViewCommon+DragDrop.swift */,
24562453
F799DF872C4B83CC003410B5 /* NCCollectionViewCommon+EasyTipView.swift */,
24572454
F799DF8A2C4B84EB003410B5 /* NCCollectionViewCommon+EndToEndInitialize.swift */,
2455+
F7CCAB502ECF315F00F8E68B /* NCCollectionViewCommon+SyncMetadata.swift */,
24582456
F778231D2C42C07C001BB94F /* NCCollectionViewCommon+MediaLayout.swift */,
24592457
F36E64F62B9245210085ABB5 /* NCCollectionViewCommon+SelectTabBarDelegate.swift */,
24602458
F7D4BF002CA1831600A5E746 /* NCCollectionViewCommonPinchGesture.swift */,
@@ -2644,7 +2642,6 @@
26442642
children = (
26452643
F7725A5F251F33BB00D125E0 /* NCFiles.storyboard */,
26462644
F7725A5E251F33BB00D125E0 /* NCFiles.swift */,
2647-
F753DBDE2E5D99B700A1AF91 /* NCFiles+SyncMetadata.swift */,
26482645
F73EFF9A2DB11EB900FD434C /* NCFiles+UIScrollViewDelegate.swift */,
26492646
F722133A2D40EF8C002F7438 /* NCFilesNavigationController.swift */,
26502647
);
@@ -4470,7 +4467,6 @@
44704467
F7D60CAF2C941ACB008FBFDD /* NCMediaPinchGesture.swift in Sources */,
44714468
F71916142E2901FB00E13E96 /* NCNetworking+Upload.swift in Sources */,
44724469
F704B5E92430C0B800632F5F /* NCCreateFormUploadConflictCell.swift in Sources */,
4473-
F7327E3D2B73B92800A462C7 /* NCNetworking+Synchronization.swift in Sources */,
44744470
F72D404923D2082500A97FD0 /* NCViewerNextcloudText.swift in Sources */,
44754471
AFCE353927E5DE0500FEA6C2 /* Shareable.swift in Sources */,
44764472
F77BB746289984CA0090FC19 /* UIViewController+Extension.swift in Sources */,
@@ -4480,7 +4476,6 @@
44804476
F785EE9D246196DF00B3F945 /* NCNetworkingE2EE.swift in Sources */,
44814477
F724377B2C10B83E00C7C68D /* NCSharePermissions.swift in Sources */,
44824478
F794E13D2BBBFF2E003693D7 /* NCMainTabBarController.swift in Sources */,
4483-
F753DBDF2E5D99C300A1AF91 /* NCFiles+SyncMetadata.swift in Sources */,
44844479
F7CBC1252BAC8B0000EC1D55 /* NCSectionFirstHeaderEmptyData.swift in Sources */,
44854480
F7D4BF3D2CA2E8D800A5E746 /* TOPasscodeKeypadView.m in Sources */,
44864481
F7D4BF3E2CA2E8D800A5E746 /* TOPasscodeSettingsKeypadView.m in Sources */,
@@ -4668,6 +4663,7 @@
46684663
F7D68FCC28CB9051009139F3 /* NCManageDatabase+DashboardWidget.swift in Sources */,
46694664
F76882292C0DD1E7001CF441 /* NCManageE2EEModel.swift in Sources */,
46704665
F799DF8B2C4B84EB003410B5 /* NCCollectionViewCommon+EndToEndInitialize.swift in Sources */,
4666+
F7CCAB512ECF316700F8E68B /* NCCollectionViewCommon+SyncMetadata.swift in Sources */,
46714667
AA8E041D2D300FDE00E7E89C /* NCShareNetworkingDelegate.swift in Sources */,
46724668
F78E2D6529AF02DB0024D4F3 /* Database.swift in Sources */,
46734669
F70CEF5623E9C7E50007035B /* UIColor+Extension.swift in Sources */,
@@ -5709,7 +5705,7 @@
57095705
CLANG_WARN_UNREACHABLE_CODE = YES;
57105706
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
57115707
COPY_PHASE_STRIP = NO;
5712-
CURRENT_PROJECT_VERSION = 2;
5708+
CURRENT_PROJECT_VERSION = 3;
57135709
DEBUG_INFORMATION_FORMAT = dwarf;
57145710
DEVELOPMENT_TEAM = NKUJUXUJ3B;
57155711
ENABLE_STRICT_OBJC_MSGSEND = YES;
@@ -5775,7 +5771,7 @@
57755771
CLANG_WARN_UNREACHABLE_CODE = YES;
57765772
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
57775773
COPY_PHASE_STRIP = NO;
5778-
CURRENT_PROJECT_VERSION = 2;
5774+
CURRENT_PROJECT_VERSION = 3;
57795775
DEVELOPMENT_TEAM = NKUJUXUJ3B;
57805776
ENABLE_STRICT_OBJC_MSGSEND = YES;
57815777
ENABLE_TESTABILITY = YES;

iOSClient/Data/NCManageDatabase+Metadata.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,4 +1281,12 @@ extension NCManageDatabase {
12811281
.count
12821282
} ?? 0
12831283
}
1284+
1285+
func metadataExistsAsync(predicate: NSPredicate) async -> Bool {
1286+
await core.performRealmReadAsync { realm in
1287+
realm.objects(tableMetadata.self)
1288+
.filter(predicate)
1289+
.first != nil
1290+
} ?? false
1291+
}
12841292
}

iOSClient/Favorites/NCFavorite.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class NCFavorite: NCCollectionViewCommon {
4040
override func viewWillDisappear(_ animated: Bool) {
4141
super.viewWillDisappear(animated)
4242

43+
stopSyncMetadata()
4344
Task {
4445
await NCNetworking.shared.networkingTasks.cancel(identifier: "NCFavorite")
4546
}
@@ -71,6 +72,7 @@ class NCFavorite: NCCollectionViewCommon {
7172
override func getServerData(forced: Bool = false) async {
7273
defer {
7374
restoreDefaultTitle()
75+
startSyncMetadata(metadatas: self.dataSource.getMetadatas())
7476
}
7577

7678
// If is already in-flight, do nothing

iOSClient/Files/NCFiles.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ class NCFiles: NCCollectionViewCommon {
1515
internal var lastScrollTime: TimeInterval = 0
1616
internal var accumulatedScrollDown: CGFloat = 0
1717

18-
internal var syncMetadatasTask: Task<Void, Never>?
19-
2018
required init?(coder aDecoder: NSCoder) {
2119
super.init(coder: aDecoder)
2220

iOSClient/Files/NCFiles+SyncMetadata.swift renamed to iOSClient/Main/Collection Common/NCCollectionViewCommon+SyncMetadata.swift

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
// SPDX-FileCopyrightText: 2025 Marino Faggiana
33
// SPDX-License-Identifier: GPL-3.0-or-later
44

5-
import UIKit
5+
import Foundation
66
import NextcloudKit
77

8-
extension NCFiles {
8+
extension NCCollectionViewCommon {
99
/// Starts a detached task that accelerates metadata synchronization for the provided items.
1010
///
1111
/// If a previous sync is still running, this method exits without starting a new one.
@@ -96,18 +96,21 @@ extension NCFiles {
9696
guard let account = metadatas.first?.account else {
9797
return
9898
}
99-
let resultsReadFile = await NCNetworking.shared.readFileAsync(serverUrlFileName: serverUrl, account: account) { task in
100-
Task {
101-
await self.networking.networkingTasks.track(identifier: identifier, task: task)
99+
100+
if !serverUrl.isEmpty {
101+
let resultsReadFile = await NCNetworking.shared.readFileAsync(serverUrlFileName: serverUrl, account: account) { task in
102+
Task {
103+
await self.networking.networkingTasks.track(identifier: identifier, task: task)
104+
}
102105
}
103-
}
104106

105-
// Validate outcome and skip E2EE items
106-
guard resultsReadFile.error == .success,
107-
let metadata = resultsReadFile.metadata,
108-
!metadata.e2eEncrypted else {
109-
nkLog(tag: global.logTagSpeedUpSyncMetadata, emoji: .info, message: "Exit: result error \(resultsReadFile.error.errorDescription) or e2ee directory \(resultsReadFile.metadata?.e2eEncrypted ?? false). Skipping this one.")
110-
return
107+
// Validate outcome and skip E2EE items
108+
guard resultsReadFile.error == .success,
109+
let metadata = resultsReadFile.metadata,
110+
!metadata.e2eEncrypted else {
111+
nkLog(tag: global.logTagSpeedUpSyncMetadata, emoji: .info, message: "Exit: result error \(resultsReadFile.error.errorDescription) or e2ee directory \(resultsReadFile.metadata?.e2eEncrypted ?? false). Skipping this one.")
112+
return
113+
}
111114
}
112115

113116
// Iterate directories and fetch only when ETag changed

iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
5050
var attributesZoomIn: UIMenuElement.Attributes = []
5151
var attributesZoomOut: UIMenuElement.Attributes = []
5252
var tipViewAccounts: EasyTipView?
53+
var syncMetadatasTask: Task<Void, Never>?
5354

5455
// DECLARE
5556
var layoutKey = ""

iOSClient/Networking/NCDownloadAction.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class NCDownloadAction: NSObject, UIDocumentInteractionControllerDelegate, NCSel
158158
} else if metadata.directory {
159159
await NCManageDatabase.shared.cleanTablesOcIds(account: metadata.account, userId: metadata.userId, urlBase: metadata.urlBase)
160160
await NCManageDatabase.shared.setDirectoryAsync(serverUrl: metadata.serverUrlFileName, offline: true, metadata: metadata)
161-
await NCNetworking.shared.synchronization(account: metadata.account, serverUrl: metadata.serverUrlFileName, userId: metadata.userId, urlBase: metadata.urlBase, metadatasInDownload: nil)
161+
await NCNetworking.shared.synchronizationDownload(account: metadata.account, serverUrl: metadata.serverUrlFileName, userId: metadata.userId, urlBase: metadata.urlBase, metadatasInDownload: nil)
162162
} else {
163163
var metadatasSynchronizationOffline: [tableMetadata] = []
164164
metadatasSynchronizationOffline.append(metadata)

iOSClient/Networking/NCNetworking+Download.swift

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,72 @@ extension NCNetworking {
223223
}
224224
}
225225
}
226+
227+
// MARK: - Synchronization Download
228+
229+
internal func synchronizationDownload(account: String, serverUrl: String, userId: String, urlBase: String, metadatasInDownload: [tableMetadata]?) async {
230+
let showHiddenFiles = NCPreferences().getShowHiddenFiles(account: account)
231+
let options = NKRequestOptions(timeout: 300, taskDescription: NCGlobal.shared.taskDescriptionSynchronization, queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)
232+
233+
nkLog(tag: self.global.logTagSync, emoji: .start, message: "Start read infinite folder: \(serverUrl)")
234+
235+
let results = await NextcloudKit.shared.readFileOrFolderAsync(serverUrlFileName: serverUrl, depth: "infinity", showHiddenFiles: showHiddenFiles, account: account, options: options) { task in
236+
Task {
237+
let identifier = await NCNetworking.shared.networkingTasks.createIdentifier(account: account,
238+
path: serverUrl,
239+
name: "readFileOrFolder")
240+
await NCNetworking.shared.networkingTasks.track(identifier: identifier, task: task)
241+
}
242+
}
243+
244+
if results.error == .success, let files = results.files {
245+
nkLog(tag: self.global.logTagSync, emoji: .success, message: "Read infinite folder: \(serverUrl)")
246+
247+
for file in files {
248+
if file.directory {
249+
let metadata = await NCManageDatabaseCreateMetadata().convertFileToMetadataAsync(file)
250+
await NCManageDatabase.shared.createDirectory(metadata: metadata)
251+
} else {
252+
if await isFileDifferent(ocId: file.ocId, fileName: file.fileName, etag: file.etag, metadatasInDownload: metadatasInDownload, userId: userId, urlBase: urlBase) {
253+
let metadata = await NCManageDatabaseCreateMetadata().convertFileToMetadataAsync(file)
254+
metadata.session = self.sessionDownloadBackground
255+
metadata.sessionSelector = NCGlobal.shared.selectorSynchronizationOffline
256+
metadata.sessionTaskIdentifier = 0
257+
metadata.sessionError = ""
258+
metadata.status = NCGlobal.shared.metadataStatusWaitDownload
259+
metadata.sessionDate = Date()
260+
261+
await NCManageDatabase.shared.addMetadataAsync(metadata)
262+
263+
nkLog(tag: self.global.logTagSync, emoji: .start, message: "File download: \(file.serverUrl)/\(file.fileName)")
264+
}
265+
}
266+
}
267+
} else {
268+
nkLog(tag: self.global.logTagSync, emoji: .error, message: "Read infinite folder: \(serverUrl), error: \(results.error.errorCode)")
269+
}
270+
271+
nkLog(tag: self.global.logTagSync, emoji: .stop, message: "Stop read infinite folder: \(serverUrl)")
272+
}
273+
274+
internal func isFileDifferent(ocId: String,
275+
fileName: String,
276+
etag: String,
277+
metadatasInDownload: [tableMetadata]?,
278+
userId: String,
279+
urlBase: String) async -> Bool {
280+
let match = metadatasInDownload?.contains { $0.ocId == ocId } ?? false
281+
if match {
282+
return false
283+
}
284+
285+
guard let localFile = await NCManageDatabase.shared.getTableLocalFileAsync(predicate: NSPredicate(format: "ocId == %@", ocId)) else {
286+
return true
287+
}
288+
let fileNamePath = self.utilityFileSystem.getDirectoryProviderStorageOcId(ocId, fileName: fileName, userId: userId, urlBase: urlBase)
289+
let size = await utilityFileSystem.fileSizeAsync(atPath: fileNamePath)
290+
let isDifferent = (localFile.etag != etag) || size == 0
291+
292+
return isDifferent
293+
}
226294
}

0 commit comments

Comments
 (0)