Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
Refactor _getFilesToBeUploaded logic (#1302)
Browse files Browse the repository at this point in the history
  • Loading branch information
ua741 authored Aug 8, 2023
2 parents 9ae658c + e2371c4 commit bb09c21
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions lib/services/remote_sync_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -489,31 +489,37 @@ class RemoteSyncService {
}

Future<List<File>> _getFilesToBeUploaded() async {
final deviceCollections = await _db.getDeviceCollections();
deviceCollections.removeWhere((element) => !element.shouldBackup);
final List<File> filesToBeUploaded = await _db.getFilesPendingForUpload();
if (!_config.shouldBackupVideos() || _shouldThrottleSync()) {
filesToBeUploaded
.removeWhere((element) => element.fileType == FileType.video);
}
if (filesToBeUploaded.isNotEmpty) {
final int prevCount = filesToBeUploaded.length;
final ignoredIDs = await IgnoredFilesService.instance.ignoredIDs;
filesToBeUploaded.removeWhere(
(file) =>
IgnoredFilesService.instance.shouldSkipUpload(ignoredIDs, file),
);
if (prevCount != filesToBeUploaded.length) {
_logger.info(
(prevCount - filesToBeUploaded.length).toString() +
" files were ignored for upload",
);
final List<File> originalFiles = await _db.getFilesPendingForUpload();
if (originalFiles.isEmpty) {
return originalFiles;
}
final bool shouldRemoveVideos =
!_config.shouldBackupVideos() || _shouldThrottleSync();
final ignoredIDs = await IgnoredFilesService.instance.ignoredIDs;
bool shouldSkipUploadFunc(File file) {
return IgnoredFilesService.instance.shouldSkipUpload(ignoredIDs, file);
}

final List<File> filesToBeUploaded = [];
int ignoredForUpload = 0;
int skippedVideos = 0;
for (var file in originalFiles) {
if (shouldRemoveVideos && file.fileType == FileType.video) {
skippedVideos++;
continue;
}
if (shouldSkipUploadFunc(file)) {
ignoredForUpload++;
continue;
}
filesToBeUploaded.add(file);
}
if (skippedVideos > 0 || ignoredForUpload > 0) {
_logger.info("Skipped $skippedVideos videos and $ignoredForUpload "
"ignored files for upload");
}
_sortByTimeAndType(filesToBeUploaded);
_logger.info(
filesToBeUploaded.length.toString() + " new files to be uploaded.",
);
_logger.info("${filesToBeUploaded.length} new files to be uploaded.");
return filesToBeUploaded;
}

Expand Down

0 comments on commit bb09c21

Please sign in to comment.