mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
fix: process upload only after successful remote sync (#22360)
Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
This commit is contained in:
parent
fea5e6783c
commit
ee3c07d049
14 changed files with 156 additions and 73 deletions
|
|
@ -91,6 +91,8 @@ class DriftUploadStatus {
|
|||
}
|
||||
}
|
||||
|
||||
enum BackupError { none, syncFailed }
|
||||
|
||||
class DriftBackupState {
|
||||
final int totalCount;
|
||||
final int backupCount;
|
||||
|
|
@ -101,6 +103,7 @@ class DriftBackupState {
|
|||
final int enqueueTotalCount;
|
||||
|
||||
final bool isCanceling;
|
||||
final BackupError error;
|
||||
|
||||
final Map<String, DriftUploadStatus> uploadItems;
|
||||
|
||||
|
|
@ -113,6 +116,7 @@ class DriftBackupState {
|
|||
required this.enqueueTotalCount,
|
||||
required this.isCanceling,
|
||||
required this.uploadItems,
|
||||
this.error = BackupError.none,
|
||||
});
|
||||
|
||||
DriftBackupState copyWith({
|
||||
|
|
@ -124,6 +128,7 @@ class DriftBackupState {
|
|||
int? enqueueTotalCount,
|
||||
bool? isCanceling,
|
||||
Map<String, DriftUploadStatus>? uploadItems,
|
||||
BackupError? error,
|
||||
}) {
|
||||
return DriftBackupState(
|
||||
totalCount: totalCount ?? this.totalCount,
|
||||
|
|
@ -134,12 +139,13 @@ class DriftBackupState {
|
|||
enqueueTotalCount: enqueueTotalCount ?? this.enqueueTotalCount,
|
||||
isCanceling: isCanceling ?? this.isCanceling,
|
||||
uploadItems: uploadItems ?? this.uploadItems,
|
||||
error: error ?? this.error,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'DriftBackupState(totalCount: $totalCount, backupCount: $backupCount, remainderCount: $remainderCount, processingCount: $processingCount, enqueueCount: $enqueueCount, enqueueTotalCount: $enqueueTotalCount, isCanceling: $isCanceling, uploadItems: $uploadItems)';
|
||||
return 'DriftBackupState(totalCount: $totalCount, backupCount: $backupCount, remainderCount: $remainderCount, processingCount: $processingCount, enqueueCount: $enqueueCount, enqueueTotalCount: $enqueueTotalCount, isCanceling: $isCanceling, uploadItems: $uploadItems, error: $error)';
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
@ -154,7 +160,8 @@ class DriftBackupState {
|
|||
other.enqueueCount == enqueueCount &&
|
||||
other.enqueueTotalCount == enqueueTotalCount &&
|
||||
other.isCanceling == isCanceling &&
|
||||
mapEquals(other.uploadItems, uploadItems);
|
||||
mapEquals(other.uploadItems, uploadItems) &&
|
||||
other.error == error;
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
@ -166,7 +173,8 @@ class DriftBackupState {
|
|||
enqueueCount.hashCode ^
|
||||
enqueueTotalCount.hashCode ^
|
||||
isCanceling.hashCode ^
|
||||
uploadItems.hashCode;
|
||||
uploadItems.hashCode ^
|
||||
error.hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -186,6 +194,7 @@ class DriftBackupNotifier extends StateNotifier<DriftBackupState> {
|
|||
enqueueTotalCount: 0,
|
||||
isCanceling: false,
|
||||
uploadItems: {},
|
||||
error: BackupError.none,
|
||||
),
|
||||
) {
|
||||
{
|
||||
|
|
@ -303,7 +312,12 @@ class DriftBackupNotifier extends StateNotifier<DriftBackupState> {
|
|||
);
|
||||
}
|
||||
|
||||
Future<void> updateError(BackupError error) async {
|
||||
state = state.copyWith(error: error);
|
||||
}
|
||||
|
||||
Future<void> startBackup(String userId) {
|
||||
state = state.copyWith(error: BackupError.none);
|
||||
return _uploadService.startBackup(userId, _updateEnqueueCount);
|
||||
}
|
||||
|
||||
|
|
@ -313,7 +327,7 @@ class DriftBackupNotifier extends StateNotifier<DriftBackupState> {
|
|||
|
||||
Future<void> cancel() async {
|
||||
dPrint(() => "Canceling backup tasks...");
|
||||
state = state.copyWith(enqueueCount: 0, enqueueTotalCount: 0, isCanceling: true);
|
||||
state = state.copyWith(enqueueCount: 0, enqueueTotalCount: 0, isCanceling: true, error: BackupError.none);
|
||||
|
||||
final activeTaskCount = await _uploadService.cancelBackup();
|
||||
|
||||
|
|
@ -329,6 +343,7 @@ class DriftBackupNotifier extends StateNotifier<DriftBackupState> {
|
|||
|
||||
Future<void> handleBackupResume(String userId) async {
|
||||
_logger.info("Resuming backup tasks...");
|
||||
state = state.copyWith(error: BackupError.none);
|
||||
final tasks = await _uploadService.getActiveTasks(kBackupGroup);
|
||||
_logger.info("Found ${tasks.length} tasks");
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue