Skip to content

High performance self-hosted photo and video management solution.

fix(mobile): don't stack an upload with itself (#31851)

Santo Shakil638b6ac55318
diff --git a/mobile/lib/domain/services/asset.service.dart b/mobile/lib/domain/services/asset.service.dart
index 7e40f426c5..cfb34097bb 100644
--- a/mobile/lib/domain/services/asset.service.dart
+++ b/mobile/lib/domain/services/asset.service.dart
@@ -204,7 +204,7 @@ class AssetService {
try {
// previous_checksum still points at the version the server had before this upload
final previousId = await _localRepository.getPreviousRemoteId(localId);
- if (previousId != null) {
+ if (previousId != null && previousId != remoteId) {
await _apiRepository.stack([remoteId, previousId]);
}
} finally {
diff --git a/mobile/test/unit/services/asset_service_test.dart b/mobile/test/unit/services/asset_service_test.dart
index c43daa1feb..7f587c09d9 100644
--- a/mobile/test/unit/services/asset_service_test.dart
+++ b/mobile/test/unit/services/asset_service_test.dart
@@ -150,6 +150,15 @@ void main() {
verify(() => mocks.localAsset.repo.updatePreviousChecksum('local', 'sha')).called(1);
});
+ test('does not stack an upload onto itself', () async {
+ when(() => mocks.localAsset.repo.getPreviousRemoteId('local')).thenAnswer((_) async => 'remote');
+
+ await sut.stackEditedUpload('local', 'remote', 'sha');
+
+ verifyNever(() => apiRepository.stack(any()));
+ verify(() => mocks.localAsset.repo.updatePreviousChecksum('local', 'sha')).called(1);
+ });
+
test('records the uploaded checksum even when the stack call fails', () async {
when(() => mocks.localAsset.repo.getPreviousRemoteId('local')).thenAnswer((_) async => 'previous');
when(() => apiRepository.stack(any())).thenThrow(Exception('offline'));