Skip to content

armgit / ente

Public Imported from GitHub
0

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

fix(remote_sync): prioritize non-updated files, push videos to back in bg for uploads

Prateek Sunal4d0a6e93ea72
diff --git a/mobile/lib/services/sync/remote_sync_service.dart b/mobile/lib/services/sync/remote_sync_service.dart
index 0897926172..77160a74fc 100644
--- a/mobile/lib/services/sync/remote_sync_service.dart
+++ b/mobile/lib/services/sync/remote_sync_service.dart
@@ -604,6 +604,22 @@ class RemoteSyncService {
await _uploader.fetchUploadURLs(toBeUploaded);
}
final List<Future> futures = [];
+
+ for (final file in filesToBeUploaded) {
+ if (_shouldThrottleSync() &&
+ futures.length >= kMaximumPermissibleUploadsInThrottledMode) {
+ _logger.info("Skipping some new files as we are throttling uploads");
+ break;
+ }
+ // prefer existing collection ID for manually uploaded files.
+ // See https://github.com/ente-io/photos-app/pull/187
+ final collectionID = file.collectionID ??
+ (await _collectionsService
+ .getOrCreateForPath(file.deviceFolder ?? 'Unknown Folder'))
+ .id;
+ _uploadFile(file, collectionID, futures);
+ }
+
for (final uploadedFileID in updatedFileIDs) {
if (_shouldThrottleSync() &&
futures.length >= kMaximumPermissibleUploadsInThrottledMode) {
@@ -635,21 +651,6 @@ class RemoteSyncService {
}
}
- for (final file in filesToBeUploaded) {
- if (_shouldThrottleSync() &&
- futures.length >= kMaximumPermissibleUploadsInThrottledMode) {
- _logger.info("Skipping some new files as we are throttling uploads");
- break;
- }
- // prefer existing collection ID for manually uploaded files.
- // See https://github.com/ente-io/photos-app/pull/187
- final collectionID = file.collectionID ??
- (await _collectionsService
- .getOrCreateForPath(file.deviceFolder ?? 'Unknown Folder'))
- .id;
- _uploadFile(file, collectionID, futures);
- }
-
try {
await Future.wait(futures);
} on InvalidFileError {
@@ -943,18 +944,15 @@ class RemoteSyncService {
// This is done to upload most recent photo first.
void _sortByTime(List<EnteFile> file) {
file.sort((first, second) {
- return second.creationTime!.compareTo(first.creationTime!);
- });
- // move updated files towards the end
- file.sort((first, second) {
- if (first.updationTime == second.updationTime) {
- return 0;
- }
- if (first.updationTime == -1) {
- return 1;
- } else {
- return -1;
+ // 1. fileType: move videos to end when in bg
+ if (!AppLifecycleService.instance.isForeground &&
+ first.fileType != second.fileType) {
+ if (first.fileType == FileType.video) return 1;
+ if (second.fileType == FileType.video) return -1;
}
+
+ // 2. creationTime descending
+ return second.creationTime!.compareTo(first.creationTime!);
});
}