Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mob][photos] Add minimal sync recovery diagnostics

Prateek Sunal59945f9cd6ca
diff --git a/mobile/apps/photos/lib/services/sync/local_sync_service.dart b/mobile/apps/photos/lib/services/sync/local_sync_service.dart
index f8ec27de24..cc070b2af5 100644
--- a/mobile/apps/photos/lib/services/sync/local_sync_service.dart
+++ b/mobile/apps/photos/lib/services/sync/local_sync_service.dart
@@ -14,6 +14,7 @@ import "package:photos/db/common/conflict_algo.dart";
import "package:photos/db/device_files_db.dart";
import "package:photos/db/file_updation_db.dart";
import "package:photos/db/files_db.dart";
+import "package:photos/extensions/logger_extension.dart";
import "package:photos/events/backup_folders_updated_event.dart";
import "package:photos/events/local_photos_updated_event.dart";
import "package:photos/events/permission_granted_event.dart";
@@ -237,6 +238,31 @@ class LocalSyncService {
),
);
}
+ final int newMappingCount =
+ localDiffResult.newPathToLocalIDs?.values.fold<int>(
+ 0,
+ (sum, ids) => sum + ids.length,
+ ) ??
+ 0;
+ final int deletedMappingCount =
+ localDiffResult.deletePathToLocalIDs?.values.fold<int>(
+ 0,
+ (sum, ids) => sum + ids.length,
+ ) ??
+ 0;
+ if (newMappingCount > 0 || deletedMappingCount > 0 || hasUnsyncedFiles) {
+ final sampleRecovered = (localDiffResult.uniqueLocalFiles ?? [])
+ .take(3)
+ .map((file) => file.localID)
+ .toList();
+ _logger.internalInfo(
+ "syncAll recovery: "
+ "newFiles=${localDiffResult.uniqueLocalFiles?.length ?? 0}, "
+ "newMappings=$newMappingCount, "
+ "deletedMappings=$deletedMappingCount, "
+ "sampleRecovered=$sampleRecovered",
+ );
+ }
_logger.info("syncAll took ${stopwatch.elapsed.inMilliseconds}ms ");
return hasUnsyncedFiles;
@@ -332,6 +358,16 @@ class LocalSyncService {
conflictAlgorithm: SqliteAsyncConflictAlgorithm.ignore,
);
_logger.info('Inserted ${files.length} out of ${allFiles.length} files');
+ if (allFiles.length != files.length) {
+ final sampleLocalIDs =
+ allFiles.take(3).map((file) => file.localID).toList();
+ _logger.internalInfo(
+ "localSync partial materialization: "
+ "from=$fromTime to=$toTime "
+ "discovered=${allFiles.length} inserted=${files.length} "
+ "sampleLocalIDs=$sampleLocalIDs",
+ );
+ }
_checkAndFireLocalAssetUpdateEvent(allFiles, files);
}
await _prefs.setInt(kDbUpdationTimeKey, toTime);
diff --git a/mobile/apps/photos/lib/services/sync/remote_sync_service.dart b/mobile/apps/photos/lib/services/sync/remote_sync_service.dart
index 8709db804f..dccf44dbed 100644
--- a/mobile/apps/photos/lib/services/sync/remote_sync_service.dart
+++ b/mobile/apps/photos/lib/services/sync/remote_sync_service.dart
@@ -10,6 +10,7 @@ import 'package:photos/core/event_bus.dart';
import 'package:photos/db/device_files_db.dart';
import 'package:photos/db/file_updation_db.dart';
import 'package:photos/db/files_db.dart';
+import 'package:photos/extensions/logger_extension.dart';
import 'package:photos/events/backup_folders_updated_event.dart';
import 'package:photos/events/collection_updated_event.dart';
import 'package:photos/events/diff_sync_complete_event.dart';
@@ -403,6 +404,7 @@ class RemoteSyncService {
for (final deviceCollection in deviceCollections) {
final Set<String> localIDsToSync =
pathIdToLocalIDs[deviceCollection.id]?.toSet() ?? {};
+ final int mappedCount = localIDsToSync.length;
if (deviceCollection.uploadStrategy == UploadStrategy.ifMissing) {
final Set<String> alreadyClaimedLocalIDs =
await _db.getLocalIDsMarkedForOrAlreadyUploaded(ownerID);
@@ -423,6 +425,12 @@ class RemoteSyncService {
}
if (localIDsToSync.isEmpty) {
+ if (mappedCount == 0) {
+ _logger.internalInfo(
+ "[${deviceCollection.name}] upload-prep empty: "
+ "pathID=${deviceCollection.id} mappedFromPath=0",
+ );
+ }
continue;
}
final collectionID = await _getCollectionID(deviceCollection);
@@ -456,6 +464,7 @@ class RemoteSyncService {
// new file entries, where we can store mapping for localID and
// corresponding collection ID
if (localIDsToSync.isNotEmpty) {
+ final int postFilterCount = localIDsToSync.length;
debugPrint(
'Adding new entries for ${localIDsToSync.length} files'
' for ${deviceCollection.name}',
@@ -476,10 +485,19 @@ class RemoteSyncService {
}
}
await _db.insertMultiple(newFilesToInsert);
- if (fileFoundForLocalIDs.length != localIDsToSync.length) {
- _logger.warning(
- "mismatch in num of filesToSync ${localIDsToSync.length} to "
- "fileSynced ${fileFoundForLocalIDs.length}",
+ final int missingFileRows =
+ postFilterCount - fileFoundForLocalIDs.length;
+ if (missingFileRows > 0) {
+ final sample =
+ localIDsToSync.difference(fileFoundForLocalIDs).take(3);
+ _logger.internalWarning(
+ "[${deviceCollection.name}] upload-prep missing rows: "
+ "pathID=${deviceCollection.id} "
+ "mappedFromPath=$mappedCount "
+ "postFilter=$postFilterCount "
+ "missingFileRows=$missingFileRows "
+ "collectionID=$collectionID "
+ "sample=${sample.toList()}",
);
}
}