π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][photos] Try deleting in batches in a better way if deletion fails in one shot by splitting a batch into two if deletion fails and repeat the process recursively on each half until deletion succeeds
ashilknaac9c73d05df
diff --git a/mobile/lib/utils/delete_file_util.dart b/mobile/lib/utils/delete_file_util.dartindex 28af47301b..576b15b18c 100644--- a/mobile/lib/utils/delete_file_util.dart+++ b/mobile/lib/utils/delete_file_util.dart@@ -653,27 +653,19 @@ Future<List<String>> _iosDeleteLocalFilesInBatchesFallback(BuildContext context,List<String> localAssetIDs,) async {- int maximumBatchSize = 1000;final List<String> deletedIDs = [];- do {- _logger.info(- "Trying to delete local files in batches with maximumBatchSize: $maximumBatchSize",- );- deletedIDs.addAll(- await deleteLocalFilesInBatches(- context,- localAssetIDs,- maximumBatchSize: maximumBatchSize,- minimumBatchSize: 10,- ),++ _logger.info(+ "Trying to delete local files in batches",+ );+ deletedIDs.addAll(+ await _deleteLocalFilesInBatchesRecursively(localAssetIDs),+ );+ if (deletedIDs.isEmpty) {+ _logger.warning(+ "Failed to delete local files in recursively batches",);- if (deletedIDs.isEmpty) {- _logger.warning(- "Failed to delete local files in batchs with maximumBatchSize: $maximumBatchSize",- );- }- maximumBatchSize = max((maximumBatchSize ~/ 2), 10);- } while (deletedIDs.isEmpty && maximumBatchSize > 10);+ }_logger.severe("iOS free-space fallback, deleted ${deletedIDs.length} files with distinct localIDs"@@ -681,3 +673,47 @@ Future<List<String>> _iosDeleteLocalFilesInBatchesFallback(return deletedIDs;}++Future<List<String>> _deleteLocalFilesInBatchesRecursively(+ List<String> localAssetIDs,+) async {+ if (localAssetIDs.isEmpty) return [];++ final deletedIDs = await _deleteLocalFiles(localAssetIDs);+ if (deletedIDs.isNotEmpty) {+ return deletedIDs;+ }++ if (localAssetIDs.length == 1) {+ _logger.warning("Failed to delete file " + localAssetIDs.first);+ return [];+ }++ final midIndex = localAssetIDs.length ~/ 2;+ final left = localAssetIDs.sublist(0, midIndex);+ final right = localAssetIDs.sublist(midIndex);++ final leftDeleted = await _deleteLocalFilesInBatchesRecursively(left);+ final rightDeleted = await _deleteLocalFilesInBatchesRecursively(right);++ return [...leftDeleted, ...rightDeleted];+}++Future<List<String>> _deleteLocalFiles(List<String> localIDs) async {+ _logger.info(+ "Trying to delete batch of size " ++ localIDs.length.toString() ++ " : " ++ localIDs.toString(),+ );++ final List<String> deletedIDs = [];+ try {+ deletedIDs.addAll(await PhotoManager.editor.deleteWithIds(localIDs));+ _logger.info("Deleted " + localIDs.toString());+ } catch (e, s) {+ _logger.severe("Could not delete batch " + localIDs.toString(), e, s);+ }++ return deletedIDs;+}