Skip to content

Commit 0f98682

Browse files
Fix duplicate AutoUpload WiFi (#4137)
* cod Signed-off-by: Marino Faggiana <marino.faggiana@nextcloud.com> * cod Signed-off-by: Marino Faggiana <marino.faggiana@nextcloud.com> * build 1 Signed-off-by: Marino Faggiana <marino.faggiana@nextcloud.com> --------- Signed-off-by: Marino Faggiana <marino.faggiana@nextcloud.com>
1 parent 19c1c03 commit 0f98682

3 files changed

Lines changed: 40 additions & 7 deletions

File tree

Nextcloud.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6035,7 +6035,7 @@
60356035
CLANG_WARN_UNREACHABLE_CODE = YES;
60366036
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
60376037
COPY_PHASE_STRIP = NO;
6038-
CURRENT_PROJECT_VERSION = 0;
6038+
CURRENT_PROJECT_VERSION = 1;
60396039
DEAD_CODE_STRIPPING = YES;
60406040
DEBUG_INFORMATION_FORMAT = dwarf;
60416041
DEVELOPMENT_TEAM = NKUJUXUJ3B;
@@ -6103,7 +6103,7 @@
61036103
CLANG_WARN_UNREACHABLE_CODE = YES;
61046104
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
61056105
COPY_PHASE_STRIP = NO;
6106-
CURRENT_PROJECT_VERSION = 0;
6106+
CURRENT_PROJECT_VERSION = 1;
61076107
DEAD_CODE_STRIPPING = YES;
61086108
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
61096109
DEVELOPMENT_TEAM = NKUJUXUJ3B;
@@ -6388,8 +6388,8 @@
63886388
isa = XCRemoteSwiftPackageReference;
63896389
repositoryURL = "https://github.com/nextcloud/NextcloudKit";
63906390
requirement = {
6391-
kind = exactVersion;
6392-
version = 7.3.3;
6391+
branch = main;
6392+
kind = branch;
63936393
};
63946394
};
63956395
F788ECC5263AAAF900ADC67F /* XCRemoteSwiftPackageReference "MarkdownKit" */ = {

iOSClient/Data/NCManageDatabase+Metadata.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,6 +1387,28 @@ extension NCManageDatabase {
13871387
} ?? 0
13881388
}
13891389

1390+
/// Filters Auto Upload metadata entries, returning only the items that are not already queued in the local database.
1391+
/// - Parameter metadatas: The detached Auto Upload metadata entries generated from Photos assets.
1392+
/// - Returns: Only metadata entries that can be safely added to the upload queue.
1393+
func filterAutoUploadMetadatasNotAlreadyQueuedAsync(_ metadatas: [tableMetadata]) async -> [tableMetadata] {
1394+
await core.performRealmReadAsync { realm in
1395+
metadatas.filter { metadata in
1396+
guard !metadata.assetLocalIdentifier.isEmpty else {
1397+
return false
1398+
}
1399+
return realm.objects(tableMetadata.self)
1400+
.filter(
1401+
"account == %@ AND sessionSelector == %@ AND assetLocalIdentifier == %@ AND session != %@",
1402+
metadata.account,
1403+
NCGlobal.shared.selectorUploadAutoUpload,
1404+
metadata.assetLocalIdentifier,
1405+
""
1406+
)
1407+
.isEmpty
1408+
}
1409+
} ?? []
1410+
}
1411+
13901412
// MARK: - helpers
13911413

13921414
/// Extracts the relative DAV folder path and filename from metadata.

iOSClient/Networking/NCAutoUpload.swift

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class NCAutoUpload: NSObject {
2929
let assetCollections = PHAssetCollection.allAlbums.filter({albumIds.contains($0.localIdentifier)})
3030
let result = await getCameraRollAssets(controller: nil, assetCollections: assetCollections, tblAccount: tableAccount(value: tblAccount))
3131
if let assets = result.assets, !assets.isEmpty, let fileNames = result.fileNames {
32-
let item = await uploadAssets(controller: nil, tblAccount: tblAccount, assets: assets, fileNames: fileNames)
32+
let item = await uploadAssets(controller: nil, tblAccount: tblAccount, assets: assets, fileNames: fileNames, filterExistingQueue: true)
3333
counter += item
3434
}
3535
}
@@ -78,14 +78,15 @@ class NCAutoUpload: NSObject {
7878
return
7979
}
8080

81-
let num = await uploadAssets(controller: controller, tblAccount: tblAccount, assets: assets, fileNames: fileNames)
81+
let num = await uploadAssets(controller: controller, tblAccount: tblAccount, assets: assets, fileNames: fileNames, filterExistingQueue: false)
8282
nkLog(debug: "Automatic upload \(num) upload")
8383
}
8484

8585
private func uploadAssets(controller: NCMainTabBarController?,
8686
tblAccount: tableAccount,
8787
assets: [PHAsset],
88-
fileNames: [String]) async -> Int {
88+
fileNames: [String],
89+
filterExistingQueue: Bool) async -> Int {
8990
let capabilities = await NKCapabilities.shared.getCapabilities(for: tblAccount.account)
9091
let autoMkcol = NCBrandOptions.shared.isServerVersion(capabilities, greaterOrEqualTo: .v33)
9192
let session = NCSession.shared.getSession(account: tblAccount.account)
@@ -167,6 +168,16 @@ class NCAutoUpload: NSObject {
167168
}
168169

169170
if !metadatas.isEmpty {
171+
let metadatasToAdd: [tableMetadata]
172+
if filterExistingQueue {
173+
metadatasToAdd = await self.database.filterAutoUploadMetadatasNotAlreadyQueuedAsync(metadatas)
174+
} else {
175+
metadatasToAdd = metadatas
176+
}
177+
guard !metadatasToAdd.isEmpty else {
178+
return 0
179+
}
180+
170181
if autoMkcol {
171182
await self.database.addMetadatasAsync(metadatas)
172183
} else {

0 commit comments

Comments
 (0)