Skip to content

Commit 96676a0

Browse files
App Processing - V 33.1.1 (#4179)
* wip Signed-off-by: Marino Faggiana <marino.faggiana@nextcloud.com> * cleanUpAsync Signed-off-by: Marino Faggiana <marino.faggiana@nextcloud.com> * wip Signed-off-by: Marino Faggiana <marino.faggiana@nextcloud.com> * build 1 test Signed-off-by: Marino Faggiana <marino.faggiana@nextcloud.com> * wip Signed-off-by: Marino Faggiana <marino.faggiana@nextcloud.com> * Clear stale server-unavailable (503) state from the previous app session Signed-off-by: Marino Faggiana <marino.faggiana@nextcloud.com> * fix Signed-off-by: Marino Faggiana <marino.faggiana@nextcloud.com> * wip Signed-off-by: Marino Faggiana <marino.faggiana@nextcloud.com> * wip Signed-off-by: Marino Faggiana <marino.faggiana@nextcloud.com> * Build 2 Signed-off-by: Marino Faggiana <marino.faggiana@nextcloud.com> * wip Signed-off-by: Marino Faggiana <marino.faggiana@nextcloud.com> * LOG Signed-off-by: Marino Faggiana <marino.faggiana@nextcloud.com> * fix hydrate Signed-off-by: Marino Faggiana <marino.faggiana@nextcloud.com> --------- Signed-off-by: Marino Faggiana <marino.faggiana@nextcloud.com>
1 parent ab96482 commit 96676a0

9 files changed

Lines changed: 301 additions & 185 deletions

Nextcloud.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6234,7 +6234,7 @@
62346234
CLANG_WARN_UNREACHABLE_CODE = YES;
62356235
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
62366236
COPY_PHASE_STRIP = NO;
6237-
CURRENT_PROJECT_VERSION = 9;
6237+
CURRENT_PROJECT_VERSION = 2;
62386238
DEAD_CODE_STRIPPING = YES;
62396239
DEBUG_INFORMATION_FORMAT = dwarf;
62406240
DEVELOPMENT_TEAM = NKUJUXUJ3B;
@@ -6261,7 +6261,7 @@
62616261
"@executable_path/Frameworks",
62626262
"@executable_path/../../Frameworks",
62636263
);
6264-
MARKETING_VERSION = 33.1.0;
6264+
MARKETING_VERSION = 33.1.1;
62656265
ONLY_ACTIVE_ARCH = YES;
62666266
OTHER_CFLAGS = "-v";
62676267
OTHER_LDFLAGS = "";
@@ -6302,7 +6302,7 @@
63026302
CLANG_WARN_UNREACHABLE_CODE = YES;
63036303
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
63046304
COPY_PHASE_STRIP = NO;
6305-
CURRENT_PROJECT_VERSION = 9;
6305+
CURRENT_PROJECT_VERSION = 2;
63066306
DEAD_CODE_STRIPPING = YES;
63076307
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
63086308
DEVELOPMENT_TEAM = NKUJUXUJ3B;
@@ -6327,7 +6327,7 @@
63276327
"@executable_path/Frameworks",
63286328
"@executable_path/../../Frameworks",
63296329
);
6330-
MARKETING_VERSION = 33.1.0;
6330+
MARKETING_VERSION = 33.1.1;
63316331
ONLY_ACTIVE_ARCH = YES;
63326332
OTHER_CFLAGS = "-v";
63336333
OTHER_LDFLAGS = "";

iOSClient/Account/NCAccount.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class NCAccount: NSObject {
194194
return
195195
}
196196
let windowScene = SceneManager.shared.getWindowScene(controller: controller)
197-
await showErrorBanner(windowScene: windowScene, text: String(format: NSLocalizedString("_account_unauthorized_", comment: ""), account), errorCode: NCGlobal.shared.errorUnauthorized401)
197+
await showErrorBanner(windowScene: windowScene, text: String(format: NSLocalizedString("_account_unauthorized_", comment: ""), account), errorCode: NCGlobal.shared.errorUnauthorized)
198198

199199
let resultsWipe = await NextcloudKit.shared.getRemoteWipeStatusAsync(serverUrl: tblAccount.urlBase, token: token, account: account) { task in
200200
Task {

iOSClient/AppDelegate+AppProcessing.swift

Lines changed: 50 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,35 @@ extension AppDelegate {
4949
scheduleAppProcessing()
5050

5151
let processingTask = Task { () -> Bool in
52+
let accounts = await NCManageDatabase.shared.getAllTableAccountAsync()
53+
let activeAccount = accounts.first(where: { $0.active })
54+
let sortedAccounts = accounts.sorted { $0.active && !$1.active }
55+
guard let activeAccount else {
56+
return true
57+
}
58+
59+
// Auto Upload
60+
await NCAutoUpload.shared.autoUploadBackgroundSync()
61+
62+
guard !Task.isCancelled else {
63+
return false
64+
}
65+
5266
// If possible, cleaning every week.
67+
//
5368
if NCPreferences().cleaningWeek() {
5469
nkLog(tag: self.global.logTagBgSync, emoji: .start, message: "Start cleaning week")
5570

56-
let tblAccounts = await NCManageDatabase.shared.getAllTableAccountAsync()
57-
for tblAccount in tblAccounts {
58-
guard !Task.isCancelled else {
59-
return false
60-
}
61-
71+
for account in accounts {
6272
await NCManageDatabase.shared.cleanTablesOcIds(
63-
account: tblAccount.account,
64-
userId: tblAccount.userId,
65-
urlBase: tblAccount.urlBase
73+
account: account.account,
74+
userId: account.userId,
75+
urlBase: account.urlBase
6676
)
67-
}
6877

69-
guard !Task.isCancelled else {
70-
return false
78+
guard !Task.isCancelled else {
79+
return false
80+
}
7181
}
7282

7383
await NCUtilityFileSystem().cleanUpAsync()
@@ -79,68 +89,59 @@ extension AppDelegate {
7989
NCPreferences().setDoneCleaningWeek()
8090

8191
nkLog(tag: self.global.logTagBgSync, emoji: .stop, message: "Stop cleaning week")
92+
}
8293

83-
return true
84-
} else {
85-
await NCAutoUpload.shared.autoUploadBackgroundSync()
86-
87-
guard !Task.isCancelled else {
88-
return false
89-
}
94+
guard !Task.isCancelled else {
95+
return false
96+
}
9097

91-
guard let account = await NCManageDatabase.shared.getActiveTableAccountAsync() else {
92-
return false
93-
}
98+
let mediaProcessor = NCMediaMetadataBackgroundProcessor()
9499

95-
let limit = 500
96-
let mediaProcessor = NCMediaMetadataBackgroundProcessor()
100+
nkLog(tag: self.global.logTagMediaBackfill,
101+
emoji: .start,
102+
message: "Start media metadata backfill for account \(activeAccount.account)")
97103

104+
let backfillStatus = await mediaProcessor.runBackfill(
105+
account: activeAccount,
106+
limit: 250
107+
) { offset, inserted, updated in
98108
nkLog(tag: self.global.logTagMediaBackfill,
99-
emoji: .start,
100-
message: "Start media metadata backfill")
101-
102-
let backfillStatus = await mediaProcessor.runBackfill(
103-
account: account,
104-
limit: limit
105-
) { offset, inserted, updated in
106-
nkLog(tag: self.global.logTagMediaBackfill,
107-
emoji: .info,
108-
message: "Media metadata backfill progress: offset \(offset) - inserted \(inserted) - updated \(updated)")
109-
}
109+
emoji: .info,
110+
message: "Media metadata backfill progress: offset \(offset) - inserted \(inserted) - updated \(updated) - account: \(activeAccount.account)")
111+
}
110112

111-
nkLog(tag: self.global.logTagMediaBackfill,
112-
emoji: backfillStatus.isSuccessful ? .stop : .error,
113-
message: backfillStatus.logMessage)
113+
nkLog(tag: self.global.logTagMediaBackfill,
114+
emoji: backfillStatus.isSuccessful ? .stop : .error,
115+
message: backfillStatus.logMessage)
114116

115-
guard backfillStatus.isSuccessful,
116-
!Task.isCancelled else {
117-
return false
118-
}
117+
guard !Task.isCancelled else {
118+
return false
119+
}
119120

121+
for account in sortedAccounts {
120122
nkLog(tag: self.global.logTagMediaPlaceholder,
121123
emoji: .start,
122-
message: "Start media metadata placeholder hydration")
124+
message: "Start media metadata placeholder hydration for account \(account.account)")
123125

124126
let hydrationStatus = await mediaProcessor.runPlaceholderHydration(
125127
account: account,
126-
limit: limit
128+
limit: 100
127129
) { succeeded in
128130
nkLog(tag: self.global.logTagMediaPlaceholder,
129131
emoji: .info,
130-
message: "Media metadata placeholder hydration progress: succeeded \(succeeded) - limit \(limit)")
132+
message: "Media metadata placeholder hydration progress: succeeded \(succeeded) account \(account.account)")
131133
}
132134

133135
nkLog(tag: self.global.logTagMediaPlaceholder,
134136
emoji: hydrationStatus.isSuccessful ? .stop : .error,
135137
message: hydrationStatus.logMessage)
136138

137-
guard hydrationStatus.isSuccessful,
138-
!Task.isCancelled else {
139+
guard !Task.isCancelled else {
139140
return false
140141
}
141-
142-
return true
143142
}
143+
144+
return true
144145
}
145146

146147
Task {

iOSClient/NCGlobal.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ final class NCGlobal: Sendable {
130130
//
131131
let errorNotModified: Int = 304
132132
let errorBadRequest: Int = 400
133-
let errorUnauthorized401: Int = 401
133+
let errorUnauthorized: Int = 401
134134
let errorForbidden: Int = 403
135135
let errorResourceNotFound: Int = 404
136136
let errorMethodNotSupported: Int = 405

iOSClient/NCMediaMetadataBackgroundProcessor.swift

Lines changed: 51 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import NextcloudKit
77

88
final class NCMediaMetadataBackgroundProcessor {
99
enum BackfillStatus {
10-
case skippedAlreadyCompleted
11-
case completed(processed: Int, inserted: Int, updated: Int)
12-
case failed(processed: Int, inserted: Int, updated: Int, errorCode: Int, errorDescription: String)
13-
case cancelled(processed: Int, inserted: Int, updated: Int)
10+
case skippedAlreadyCompleted(account: String)
11+
case completed(account: String, processed: Int, inserted: Int, updated: Int)
12+
case failed(account: String, processed: Int, inserted: Int, updated: Int, errorCode: Int, errorDescription: String)
13+
case cancelled(account: String, processed: Int, inserted: Int, updated: Int)
1414

1515
var isSuccessful: Bool {
1616
switch self {
@@ -23,22 +23,25 @@ final class NCMediaMetadataBackgroundProcessor {
2323

2424
var logMessage: String {
2525
switch self {
26-
case .skippedAlreadyCompleted:
27-
return "Media metadata backfill skipped: cycle already completed"
28-
case .completed(let processed, let inserted, let updated):
29-
return "Media metadata backfill completed: processed \(processed) - inserted \(inserted) - updated \(updated)"
30-
case .failed(let processed, let inserted, let updated, let errorCode, let errorDescription):
31-
return "Media metadata backfill failed: processed \(processed) - inserted \(inserted) - updated \(updated) - error \(errorCode) \(errorDescription)"
32-
case .cancelled(let processed, let inserted, let updated):
33-
return "Media metadata backfill cancelled: processed \(processed) - inserted \(inserted) - updated \(updated)"
26+
case .skippedAlreadyCompleted(let account):
27+
return "Media metadata backfill skipped for account \(account): cycle already completed"
28+
29+
case .completed(let account, let processed, let inserted, let updated):
30+
return "Media metadata backfill completed for account \(account): processed \(processed) - inserted \(inserted) - updated \(updated)"
31+
32+
case .failed(let account, let processed, let inserted, let updated, let errorCode, let errorDescription):
33+
return "Media metadata backfill failed for account \(account): processed \(processed) - inserted \(inserted) - updated \(updated) - error \(errorCode) \(errorDescription)"
34+
35+
case .cancelled(let account, let processed, let inserted, let updated):
36+
return "Media metadata backfill cancelled for account \(account): processed \(processed) - inserted \(inserted) - updated \(updated)"
3437
}
3538
}
3639
}
3740

3841
enum PlaceholderHydrationStatus {
39-
case skippedNoPlaceholders
40-
case completed(total: Int, succeeded: Int, failed: Int)
41-
case cancelled(total: Int, succeeded: Int, failed: Int)
42+
case skippedNoPlaceholders(account: String)
43+
case completed(account: String, total: Int, succeeded: Int, failed: Int)
44+
case cancelled(account: String, total: Int, succeeded: Int, failed: Int)
4245

4346
var isSuccessful: Bool {
4447
switch self {
@@ -51,14 +54,16 @@ final class NCMediaMetadataBackgroundProcessor {
5154

5255
var logMessage: String {
5356
switch self {
54-
case .skippedNoPlaceholders:
55-
return "Media metadata placeholder hydration skipped: no placeholders found"
56-
case .completed(let total, let succeeded, let failed):
57+
case .skippedNoPlaceholders(let account):
58+
return "Media metadata placeholder hydration skipped for account \(account): no placeholders found"
59+
60+
case .completed(let account, let total, let succeeded, let failed):
5761
let pending = max(0, total - succeeded - failed)
58-
return "Media metadata placeholder hydration completed: total \(total) - succeeded \(succeeded) - failed \(failed) - pending \(pending)"
59-
case .cancelled(let total, let succeeded, let failed):
62+
return "Media metadata placeholder hydration completed for account \(account): total \(total) - succeeded \(succeeded) - failed \(failed) - pending \(pending)"
63+
64+
case .cancelled(let account, let total, let succeeded, let failed):
6065
let pending = max(0, total - succeeded - failed)
61-
return "Media metadata placeholder hydration cancelled: total \(total) - succeeded \(succeeded) - failed \(failed) - pending \(pending)"
66+
return "Media metadata placeholder hydration cancelled for account \(account): total \(total) - succeeded \(succeeded) - failed \(failed) - pending \(pending)"
6267
}
6368
}
6469
}
@@ -73,7 +78,7 @@ final class NCMediaMetadataBackgroundProcessor {
7378
let state = await database.getMediaMetadataBackfillAsync(account: account.account)
7479

7580
guard state?.lastCompletedCycleDate == nil else {
76-
return .skippedAlreadyCompleted
81+
return .skippedAlreadyCompleted(account: account.account)
7782
}
7883

7984
var offset = state?.offset ?? 0
@@ -94,14 +99,15 @@ final class NCMediaMetadataBackgroundProcessor {
9499
)
95100

96101
guard !Task.isCancelled else {
97-
return .cancelled(processed: processed, inserted: inserted, updated: updated)
102+
return .cancelled(account: account.account, processed: processed, inserted: inserted, updated: updated)
98103
}
99104

100105
guard let files = result.files else {
101106
let errorCode = result.error?.errorCode ?? 0
102107
let errorDescription = result.error?.errorDescription ?? ""
103108

104109
return .failed(
110+
account: account.account,
105111
processed: processed,
106112
inserted: inserted,
107113
updated: updated,
@@ -112,7 +118,7 @@ final class NCMediaMetadataBackgroundProcessor {
112118

113119
guard !files.isEmpty else {
114120
await database.completeMediaMetadataBackfillAsync(account: account.account)
115-
return .completed(processed: processed, inserted: inserted, updated: updated)
121+
return .completed(account: account.account, processed: processed, inserted: inserted, updated: updated)
116122
}
117123

118124
let ocIds = files.compactMap(\.ocId)
@@ -131,7 +137,7 @@ final class NCMediaMetadataBackgroundProcessor {
131137
await update(offset, resultPlaceholders.inserted, resultPlaceholders.updated)
132138

133139
guard !Task.isCancelled else {
134-
return .cancelled(processed: processed, inserted: inserted, updated: updated)
140+
return .cancelled(account: account.account, processed: processed, inserted: inserted, updated: updated)
135141
}
136142

137143
await database.updateMediaMetadataBackfillAsync(
@@ -141,13 +147,13 @@ final class NCMediaMetadataBackgroundProcessor {
141147

142148
guard files.count == limit else {
143149
await database.completeMediaMetadataBackfillAsync(account: account.account)
144-
return .completed(processed: processed, inserted: inserted, updated: updated)
150+
return .completed(account: account.account, processed: processed, inserted: inserted, updated: updated)
145151
}
146152

147153
token = result.token
148154
}
149155

150-
return .cancelled(processed: processed, inserted: inserted, updated: updated)
156+
return .cancelled(account: account.account, processed: processed, inserted: inserted, updated: updated)
151157
}
152158

153159
/// Completes media metadata placeholders by retrieving and storing their full properties.
@@ -171,7 +177,7 @@ final class NCMediaMetadataBackgroundProcessor {
171177
ascending: false,
172178
limit: limit
173179
), !metadatas.isEmpty else {
174-
return .skippedNoPlaceholders
180+
return .skippedNoPlaceholders(account: account.account)
175181
}
176182

177183
let total = metadatas.count
@@ -187,16 +193,25 @@ final class NCMediaMetadataBackgroundProcessor {
187193
account: metadata.account
188194
)
189195

190-
guard !Task.isCancelled,
191-
result.error == .success,
192-
let file = result.files?.first else {
196+
guard !Task.isCancelled else {
193197
return false
194198
}
195199

196-
let metadata = await NCManageDatabaseCreateMetadata().convertFileToMetadataAsync(file)
197-
await database.addMetadataAsync(metadata)
200+
switch result.error.errorCode {
201+
case 0:
202+
if let file = result.files?.first {
203+
let metadata = await NCManageDatabaseCreateMetadata().convertFileToMetadataAsync(file)
204+
await database.addMetadataAsync(metadata)
205+
}
206+
return true
207+
208+
case 404:
209+
await database.deleteMetadataAsync(ocId: metadata.ocId)
210+
return true
198211

199-
return true
212+
default:
213+
return false
214+
}
200215
}
201216

202217
await withTaskGroup(of: Bool.self) { group in
@@ -235,11 +250,11 @@ final class NCMediaMetadataBackgroundProcessor {
235250
}
236251

237252
guard !Task.isCancelled else {
238-
return .cancelled(total: total, succeeded: succeeded, failed: failed)
253+
return .cancelled(account: account.account, total: total, succeeded: succeeded, failed: failed)
239254
}
240255

241256
await update(succeeded)
242257

243-
return .completed(total: total, succeeded: succeeded, failed: failed)
258+
return .completed(account: account.account, total: total, succeeded: succeeded, failed: failed)
244259
}
245260
}

0 commit comments

Comments
 (0)