Skip to content

armgit / ente

Public Imported from GitHub
0

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

Exclude iCloud shared album files from free up space

ashilkn8600d56c25a0
diff --git a/mobile/apps/photos/lib/db/device_files_db.dart b/mobile/apps/photos/lib/db/device_files_db.dart
index 0e56b1a73b..919ef97e45 100644
--- a/mobile/apps/photos/lib/db/device_files_db.dart
+++ b/mobile/apps/photos/lib/db/device_files_db.dart
@@ -3,10 +3,10 @@ import 'package:flutter/foundation.dart';
import 'package:logging/logging.dart';
import 'package:photo_manager/photo_manager.dart';
import 'package:photos/db/files_db.dart';
-import 'package:photos/models/backup_status.dart';
import 'package:photos/models/device_collection.dart';
import 'package:photos/models/file/file.dart';
import 'package:photos/models/file_load_result.dart';
+import 'package:photos/models/freeable_space_info.dart';
import 'package:photos/models/upload_strategy.dart';
import "package:photos/services/sync/import/model.dart";
import 'package:sqflite/sqlite_api.dart';
@@ -353,10 +353,11 @@ extension DeviceFiles on FilesDB {
return FileLoadResult(dedupe, files.length == limit);
}
- Future<BackedUpFileIDs> getBackedUpForDeviceCollection(
+ Future<FreeableFileIDs> getFreeableFileIDsForDeviceCollection(
String pathID,
- int ownerID,
- ) async {
+ int ownerID, {
+ Set<String> excludeLocalIDs = const {},
+ }) async {
final db = await sqliteAsyncDB;
const String rawQuery = '''
SELECT ${FilesDB.columnLocalID}, ${FilesDB.columnUploadedFileID},
@@ -375,6 +376,7 @@ extension DeviceFiles on FilesDB {
int localSize = 0;
for (final result in results) {
final String localID = result[FilesDB.columnLocalID] as String;
+ if (excludeLocalIDs.contains(localID)) continue;
final int? fileSize = result[FilesDB.columnFileSize] as int?;
if (!localIDs.contains(localID) && fileSize != null) {
localSize += fileSize;
@@ -382,7 +384,7 @@ extension DeviceFiles on FilesDB {
localIDs.add(localID);
uploadedIDs.add(result[FilesDB.columnUploadedFileID] as int);
}
- return BackedUpFileIDs(localIDs.toList(), uploadedIDs.toList(), localSize);
+ return FreeableFileIDs(localIDs.toList(), uploadedIDs.toList(), localSize);
}
Future<List<DeviceCollection>> getDeviceCollections({
diff --git a/mobile/apps/photos/lib/db/files_db.dart b/mobile/apps/photos/lib/db/files_db.dart
index fbf43be3b8..1533421655 100644
--- a/mobile/apps/photos/lib/db/files_db.dart
+++ b/mobile/apps/photos/lib/db/files_db.dart
@@ -9,10 +9,10 @@ import 'package:path/path.dart';
import 'package:path_provider/path_provider.dart';
import "package:photos/db/common/base.dart";
import "package:photos/db/common/conflict_algo.dart";
-import 'package:photos/models/backup_status.dart';
import 'package:photos/models/file/file.dart';
import 'package:photos/models/file/file_type.dart';
import 'package:photos/models/file_load_result.dart';
+import 'package:photos/models/freeable_space_info.dart';
import 'package:photos/models/location/location.dart';
import "package:photos/models/metadata/common_keys.dart";
import "package:photos/services/filter/db_filters.dart";
@@ -660,7 +660,9 @@ class FilesDB with SqlDbBase {
return (ids, hash);
}
- Future<BackedUpFileIDs> getBackedUpIDs() async {
+ Future<FreeableFileIDs> getFreeableFileIDs({
+ Set<String> excludeLocalIDs = const {},
+ }) async {
final db = await instance.sqliteAsyncDB;
final results = await db.getAll(
'SELECT $columnLocalID, $columnUploadedFileID, $columnFileSize FROM $filesTable'
@@ -671,14 +673,15 @@ class FilesDB with SqlDbBase {
int localSize = 0;
for (final result in results) {
final String localID = result[columnLocalID] as String;
+ if (excludeLocalIDs.contains(localID)) continue;
final int? fileSize = result[columnFileSize] as int?;
if (!localIDs.contains(localID) && fileSize != null) {
localSize += fileSize;
}
- localIDs.add(result[columnLocalID] as String);
+ localIDs.add(localID);
uploadedIDs.add(result[columnUploadedFileID] as int);
}
- return BackedUpFileIDs(localIDs.toList(), uploadedIDs.toList(), localSize);
+ return FreeableFileIDs(localIDs.toList(), uploadedIDs.toList(), localSize);
}
Future<FileLoadResult> getAllPendingOrUploadedFiles(
diff --git a/mobile/apps/photos/lib/db/ml/db.dart b/mobile/apps/photos/lib/db/ml/db.dart
index e18dde8291..42aafe2af2 100644
--- a/mobile/apps/photos/lib/db/ml/db.dart
+++ b/mobile/apps/photos/lib/db/ml/db.dart
@@ -282,7 +282,6 @@ class MLDataDB with SqlDbBase implements IMLDataDB<int> {
}
}
-
@override
Future<Iterable<Uint8List>> getFaceEmbeddingsForCluster(
String clusterID, {
@@ -1353,8 +1352,10 @@ class MLDataDB with SqlDbBase implements IMLDataDB<int> {
"Got ${fileIDs.length} valid embeddings, $weirdCount weird embeddings",
);
- await _clipVectorDB
- .bulkInsertEmbeddings(fileIDs: fileIDs, embeddings: embeddings);
+ await _clipVectorDB.bulkInsertEmbeddings(
+ fileIDs: fileIDs,
+ embeddings: embeddings,
+ );
_logger.info("Inserted ${fileIDs.length} embeddings to ClipVectorDB");
processedCount += fileIDs.length;
offset += batchSize;
diff --git a/mobile/apps/photos/lib/models/backup_status.dart b/mobile/apps/photos/lib/models/freeable_space_info.dart
similarity index 65%
rename from mobile/apps/photos/lib/models/backup_status.dart
rename to mobile/apps/photos/lib/models/freeable_space_info.dart
index 0ce706532c..f97f83c380 100644
--- a/mobile/apps/photos/lib/models/backup_status.dart
+++ b/mobile/apps/photos/lib/models/freeable_space_info.dart
@@ -1,11 +1,11 @@
-class BackupStatus {
+class FreeableSpaceInfo {
final List<String> localIDs;
final int size;
- BackupStatus(this.localIDs, this.size);
+ FreeableSpaceInfo(this.localIDs, this.size);
}
-class BackedUpFileIDs {
+class FreeableFileIDs {
final List<String> localIDs;
final List<int> uploadedIDs;
// localSize indicates the approximate size of the files on the device.
@@ -13,5 +13,5 @@ class BackedUpFileIDs {
// uploaded
final int localSize;
- BackedUpFileIDs(this.localIDs, this.uploadedIDs, this.localSize);
+ FreeableFileIDs(this.localIDs, this.uploadedIDs, this.localSize);
}
diff --git a/mobile/apps/photos/lib/models/memories/memories_cache.dart b/mobile/apps/photos/lib/models/memories/memories_cache.dart
index 1e608cb66b..9489f2eba7 100644
--- a/mobile/apps/photos/lib/models/memories/memories_cache.dart
+++ b/mobile/apps/photos/lib/models/memories/memories_cache.dart
@@ -203,8 +203,7 @@ class ToShowMemory {
return {
'title': title,
'fileUploadedIDs': fileUploadedIDs.toList(),
- if (fileLocalIntIDs != null)
- 'fileLocalIntIDs': fileLocalIntIDs!.toList(),
+ if (fileLocalIntIDs != null) 'fileLocalIntIDs': fileLocalIntIDs!.toList(),
'type': type.toString().split('.').last,
'firstTimeToShow': firstTimeToShow,
'lastTimeToShow': lastTimeToShow,
diff --git a/mobile/apps/photos/lib/services/files_service.dart b/mobile/apps/photos/lib/services/files_service.dart
index 375d2ed129..29c4e28b28 100644
--- a/mobile/apps/photos/lib/services/files_service.dart
+++ b/mobile/apps/photos/lib/services/files_service.dart
@@ -1,17 +1,20 @@
+import 'dart:io';
+
import 'package:dio/dio.dart';
import 'package:ente_pure_utils/ente_pure_utils.dart';
import "package:flutter/material.dart";
import "package:latlong2/latlong.dart";
import 'package:logging/logging.dart';
import 'package:path/path.dart';
+import 'package:photo_manager/photo_manager.dart' hide LatLng;
import 'package:photos/core/configuration.dart';
import 'package:photos/core/network/network.dart';
import "package:photos/db/device_files_db.dart";
import 'package:photos/db/files_db.dart';
import "package:photos/generated/l10n.dart";
-import "package:photos/models/backup_status.dart";
import 'package:photos/models/file/file.dart';
import "package:photos/models/file_load_result.dart";
+import "package:photos/models/freeable_space_info.dart";
import "package:photos/models/metadata/file_magic.dart";
import 'package:photos/services/file_magic_service.dart';
import "package:photos/services/ignored_files_service.dart";
@@ -72,15 +75,19 @@ class FilesService {
}
}
- Future<BackupStatus> getBackupStatus({String? pathID}) async {
- BackedUpFileIDs ids;
+ Future<FreeableSpaceInfo> getFreeableSpaceInfo({String? pathID}) async {
+ final excludeLocalIDs = await _getICloudSharedAlbumAssetIDs();
+ FreeableFileIDs ids;
final bool hasMigratedSize = await FilesService.instance.hasMigratedSizes();
if (pathID == null) {
- ids = await FilesDB.instance.getBackedUpIDs();
+ ids = await FilesDB.instance.getFreeableFileIDs(
+ excludeLocalIDs: excludeLocalIDs,
+ );
} else {
- ids = await FilesDB.instance.getBackedUpForDeviceCollection(
+ ids = await FilesDB.instance.getFreeableFileIDsForDeviceCollection(
pathID,
Configuration.instance.getUserID()!,
+ excludeLocalIDs: excludeLocalIDs,
);
}
late int size;
@@ -89,7 +96,38 @@ class FilesService {
} else {
size = await _getFileSize(ids.uploadedIDs);
}
- return BackupStatus(ids.localIDs, size);
+ return FreeableSpaceInfo(ids.localIDs, size);
+ }
+
+ /// Returns local asset IDs that belong to iCloud shared albums on iOS.
+ /// These assets cannot be deleted via PhotoManager and must be excluded
+ /// from the free-up-space operation.
+ Future<Set<String>> _getICloudSharedAlbumAssetIDs() async {
+ if (!Platform.isIOS) return {};
+
+ final paths = await PhotoManager.getAssetPathList(
+ hasAll: false,
+ type: RequestType.common,
+ pathFilterOption: const PMPathFilter(
+ darwin: PMDarwinPathFilter(
+ type: [PMDarwinAssetCollectionType.album],
+ subType: [PMDarwinAssetCollectionSubtype.albumCloudShared],
+ ),
+ ),
+ );
+
+ final Set<String> sharedIDs = {};
+ for (final path in paths) {
+ final count = await path.assetCountAsync;
+ final assets = await path.getAssetListRange(start: 0, end: count);
+ for (final asset in assets) {
+ sharedIDs.add(asset.id);
+ }
+ }
+ _logger.info(
+ "Found ${sharedIDs.length} assets in iCloud shared albums",
+ );
+ return sharedIDs;
}
Future<int> _getFileSize(List<int> fileIDs) async {
diff --git a/mobile/apps/photos/lib/services/magic_cache_service.dart b/mobile/apps/photos/lib/services/magic_cache_service.dart
index defdc5e5f3..c98fbe80be 100644
--- a/mobile/apps/photos/lib/services/magic_cache_service.dart
+++ b/mobile/apps/photos/lib/services/magic_cache_service.dart
@@ -66,8 +66,7 @@ class MagicCache {
return {
'title': title,
'fileUploadedIDs': fileUploadedIDs.toList(),
- if (fileLocalIntIDs != null)
- 'fileLocalIntIDs': fileLocalIntIDs!.toList(),
+ if (fileLocalIntIDs != null) 'fileLocalIntIDs': fileLocalIntIDs!.toList(),
};
}
@@ -129,19 +128,16 @@ GenericSearchResult? toGenericSearchResult(
List<EnteFile> enteFilesInMagicCache,
Map<int, int> fileIdToPositionMap, {
Map<String, int>? localIdToIntId,
-}
-) {
+}) {
if (enteFilesInMagicCache.isEmpty) {
return null;
}
if (!prompt.recentFirst) {
enteFilesInMagicCache.sort((a, b) {
- final idA = localIdToIntId != null
- ? localIdToIntId[a.localID]
- : _magicFileId(a);
- final idB = localIdToIntId != null
- ? localIdToIntId[b.localID]
- : _magicFileId(b);
+ final idA =
+ localIdToIntId != null ? localIdToIntId[a.localID] : _magicFileId(a);
+ final idB =
+ localIdToIntId != null ? localIdToIntId[b.localID] : _magicFileId(b);
final posA = idA != null ? fileIdToPositionMap[idA] : null;
final posB = idB != null ? fileIdToPositionMap[idB] : null;
if (posA == null && posB == null) return 0;
@@ -429,7 +425,8 @@ class MagicCacheService {
}
for (final p in prompts) {
final cache = cacheByTitle[p.title];
- final localIntIdsForPrompt = cache?.fileLocalIntIDs ?? const <int>[];
+ final localIntIdsForPrompt =
+ cache?.fileLocalIntIDs ?? const <int>[];
final filesForPrompt = <EnteFile>[];
for (final localIntId in localIntIdsForPrompt) {
final localId = localIdMap[localIntId];
@@ -513,5 +510,4 @@ class MagicCacheService {
_logger.info('magic result count $matchCount $t');
return results;
}
-
}
diff --git a/mobile/apps/photos/lib/services/memories_cache_service.dart b/mobile/apps/photos/lib/services/memories_cache_service.dart
index 494ec96e52..1ba4b26a63 100644
--- a/mobile/apps/photos/lib/services/memories_cache_service.dart
+++ b/mobile/apps/photos/lib/services/memories_cache_service.dart
@@ -105,11 +105,13 @@ class MemoriesCacheService {
});
}
- String get _lastCacheUpdateKey =>
- isOfflineMode ? "${_lastMemoriesCacheUpdateTimeKey}_offline" : _lastMemoriesCacheUpdateTimeKey;
+ String get _lastCacheUpdateKey => isOfflineMode
+ ? "${_lastMemoriesCacheUpdateTimeKey}_offline"
+ : _lastMemoriesCacheUpdateTimeKey;
- String get _shouldUpdateKey =>
- isOfflineMode ? "${_shouldUpdateCacheKey}_offline" : _shouldUpdateCacheKey;
+ String get _shouldUpdateKey => isOfflineMode
+ ? "${_shouldUpdateCacheKey}_offline"
+ : _shouldUpdateCacheKey;
int get lastMemoriesCacheUpdateTime {
return _prefs.getInt(_lastCacheUpdateKey) ?? 0;
@@ -137,7 +139,9 @@ class MemoriesCacheService {
localSettings.isSmartMemoriesEnabled;
bool get curatedMemoriesOption =>
- showAnyMemories && hasGrantedMLConsent && localSettings.isMLLocalIndexingEnabled;
+ showAnyMemories &&
+ hasGrantedMLConsent &&
+ localSettings.isMLLocalIndexingEnabled;
void _checkIfTimeToUpdateCache() {
if (!enableSmartMemories) {
@@ -402,8 +406,7 @@ class MemoriesCacheService {
}
final localIdToFile = <String, EnteFile>{};
if (minimalLocalIntIds.isNotEmpty) {
- final localIdMap =
- await OfflineFilesDB.instance.getLocalIdsForIntIds(
+ final localIdMap = await OfflineFilesDB.instance.getLocalIdsForIntIds(
minimalLocalIntIds,
);
final allFiles = await SearchService.instance.getAllFilesForSearch();
diff --git a/mobile/apps/photos/lib/services/search_service.dart b/mobile/apps/photos/lib/services/search_service.dart
index bab7323674..6ce7d4b81e 100644
--- a/mobile/apps/photos/lib/services/search_service.dart
+++ b/mobile/apps/photos/lib/services/search_service.dart
@@ -894,8 +894,7 @@ class SearchService {
}) async {
try {
if (isOfflineMode) {
- final effectiveMinClusterSize =
- minClusterSize > 5 ? 5 : minClusterSize;
+ final effectiveMinClusterSize = minClusterSize > 5 ? 5 : minClusterSize;
if (showIgnoredOnly) {
return [];
}
diff --git a/mobile/apps/photos/lib/services/smart_memories_service.dart b/mobile/apps/photos/lib/services/smart_memories_service.dart
index 897df8dbea..e9aaad00bc 100644
--- a/mobile/apps/photos/lib/services/smart_memories_service.dart
+++ b/mobile/apps/photos/lib/services/smart_memories_service.dart
@@ -336,8 +336,7 @@ class SmartMemoriesService {
return filtered;
}
- Future<(Set<EnteFile>, Map<int, EnteFile>)>
- _getFilesAndMapForMemories({
+ Future<(Set<EnteFile>, Map<int, EnteFile>)> _getFilesAndMapForMemories({
bool useGeneratedIds = false,
bool requireLocalId = false,
bool useLocalIntIds = false,
@@ -582,8 +581,7 @@ class SmartMemoriesService {
}
// Filler memories
- final fillerMemories =
- await _getFillerResults(
+ final fillerMemories = await _getFillerResults(
allFiles,
now,
seenTimes: seenTimes,
@@ -1907,30 +1905,26 @@ class SmartMemoriesService {
final diff = fileTimeInYear.difference(currentTime);
if (!diff.isNegative && diff < kMemoriesUpdateFrequency) {
final yearsAgo = currentYear - fileDate.year;
- yearsAgoToMemories
- .putIfAbsent(yearsAgo, () => [])
- .add(
- Memory.fromFile(
- file,
- seenTimes,
- seenTimeKey: _seenTimeKeyForFile(file, localIdToIntId),
- ),
- );
+ yearsAgoToMemories.putIfAbsent(yearsAgo, () => []).add(
+ Memory.fromFile(
+ file,
+ seenTimes,
+ seenTimeKey: _seenTimeKeyForFile(file, localIdToIntId),
+ ),
+ );
} else if (almostYearEnd) {
final altDiff = fileDate.copyWith(year: currentYear + 1).difference(
currentTime,
);
if (!altDiff.isNegative && altDiff < kMemoriesUpdateFrequency) {
final yearsAgo = currentYear - fileDate.year + 1;
- yearsAgoToMemories
- .putIfAbsent(yearsAgo, () => [])
- .add(
- Memory.fromFile(
- file,
- seenTimes,
- seenTimeKey: _seenTimeKeyForFile(file, localIdToIntId),
- ),
- );
+ yearsAgoToMemories.putIfAbsent(yearsAgo, () => []).add(
+ Memory.fromFile(
+ file,
+ seenTimes,
+ seenTimeKey: _seenTimeKeyForFile(file, localIdToIntId),
+ ),
+ );
}
}
}
@@ -2031,30 +2025,26 @@ class SmartMemoriesService {
final fileTimeInYear = fileDate.copyWith(year: currentYear);
final diff = fileTimeInYear.difference(startPoint);
if (!diff.isNegative && diff < diffThreshold) {
- daysToMemories
- .putIfAbsent(diff.inDays, () => [])
- .add(
- Memory.fromFile(
- file,
- seenTimes,
- seenTimeKey: _seenTimeKeyForFile(file, localIdToIntId),
- ),
- );
+ daysToMemories.putIfAbsent(diff.inDays, () => []).add(
+ Memory.fromFile(
+ file,
+ seenTimes,
+ seenTimeKey: _seenTimeKeyForFile(file, localIdToIntId),
+ ),
+ );
daysToYears.putIfAbsent(diff.inDays, () => []).add(fileDate.year);
} else if (almostYearEnd) {
final altDiff = fileDate.copyWith(year: currentYear + 1).difference(
currentTime,
);
if (!altDiff.isNegative && altDiff < diffThreshold) {
- daysToMemories
- .putIfAbsent(altDiff.inDays, () => [])
- .add(
- Memory.fromFile(
- file,
- seenTimes,
- seenTimeKey: _seenTimeKeyForFile(file, localIdToIntId),
- ),
- );
+ daysToMemories.putIfAbsent(altDiff.inDays, () => []).add(
+ Memory.fromFile(
+ file,
+ seenTimes,
+ seenTimeKey: _seenTimeKeyForFile(file, localIdToIntId),
+ ),
+ );
daysToYears.putIfAbsent(altDiff.inDays, () => []).add(fileDate.year);
}
}
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 d67839e720..ab99522ef0 100644
--- a/mobile/apps/photos/lib/services/sync/local_sync_service.dart
+++ b/mobile/apps/photos/lib/services/sync/local_sync_service.dart
@@ -165,7 +165,7 @@ class LocalSyncService {
Future<bool> syncAll() async {
if (!Configuration.instance.isLoggedIn()) {
- if(!isOfflineMode) {
+ if (!isOfflineMode) {
_logger.warning("syncAll called when user is not logged in");
return false;
}
diff --git a/mobile/apps/photos/lib/services/text_embeddings_cache_service.dart b/mobile/apps/photos/lib/services/text_embeddings_cache_service.dart
index 6702fae2a0..52a1380fb1 100644
--- a/mobile/apps/photos/lib/services/text_embeddings_cache_service.dart
+++ b/mobile/apps/photos/lib/services/text_embeddings_cache_service.dart
@@ -13,8 +13,7 @@ class TextEmbeddingsCacheService {
final mlDataDB =
isOfflineMode ? MLDataDB.offlineInstance : MLDataDB.instance;
// 1. Check database cache
- final dbResult =
- await mlDataDB.getRepeatedTextEmbeddingCache(query);
+ final dbResult = await mlDataDB.getRepeatedTextEmbeddingCache(query);
if (dbResult != null) {
_logger.info('Text embedding cache hit for query');
return dbResult;
diff --git a/mobile/apps/photos/lib/ui/home/status_bar_widget.dart b/mobile/apps/photos/lib/ui/home/status_bar_widget.dart
index 6906753fca..128dba1f39 100644
--- a/mobile/apps/photos/lib/ui/home/status_bar_widget.dart
+++ b/mobile/apps/photos/lib/ui/home/status_bar_widget.dart
@@ -81,8 +81,8 @@ class _StatusBarWidgetState extends State<StatusBarWidget> {
_notificationSubscription =
Bus.instance.on<NotificationEvent>().listen((event) {
if (mounted) {
- _showMlBanner = !hasGrantedMLConsent &&
- !localSettings.hasSeenMLEnablingBanner;
+ _showMlBanner =
+ !hasGrantedMLConsent && !localSettings.hasSeenMLEnablingBanner;
setState(() {});
}
});
diff --git a/mobile/apps/photos/lib/ui/settings/backup/free_space_options.dart b/mobile/apps/photos/lib/ui/settings/backup/free_space_options.dart
index 19ce1b0894..7f30c417da 100644
--- a/mobile/apps/photos/lib/ui/settings/backup/free_space_options.dart
+++ b/mobile/apps/photos/lib/ui/settings/backup/free_space_options.dart
@@ -5,8 +5,8 @@ import "package:ente_pure_utils/ente_pure_utils.dart";
import "package:flutter/foundation.dart" show kDebugMode;
import 'package:flutter/material.dart';
import "package:photos/generated/l10n.dart";
-import "package:photos/models/backup_status.dart";
import "package:photos/models/duplicate_files.dart";
+import "package:photos/models/freeable_space_info.dart";
import "package:photos/service_locator.dart";
import "package:photos/services/collections_service.dart";
import "package:photos/services/deduplication_service.dart";
@@ -227,9 +227,9 @@ class _FreeUpSpaceOptionsScreenState extends State<FreeUpSpaceOptionsScreen> {
}
Future<void> _onFreeUpDeviceSpaceTapped() async {
- BackupStatus status;
+ FreeableSpaceInfo status;
try {
- status = await FilesService.instance.getBackupStatus();
+ status = await FilesService.instance.getFreeableSpaceInfo();
} catch (e) {
await showGenericErrorDialog(
context: context,
@@ -317,7 +317,7 @@ class _FreeUpSpaceOptionsScreenState extends State<FreeUpSpaceOptionsScreen> {
}
}
- void _showSpaceFreedDialog(BackupStatus status) {
+ void _showSpaceFreedDialog(FreeableSpaceInfo status) {
if (localSettings.shouldPromptToRateUs()) {
localSettings.setRateUsShownCount(
localSettings.getRateUsShownCount() + 1,
diff --git a/mobile/apps/photos/lib/ui/tools/free_space_page.dart b/mobile/apps/photos/lib/ui/tools/free_space_page.dart
index 22e977f816..5cb7c8d422 100644
--- a/mobile/apps/photos/lib/ui/tools/free_space_page.dart
+++ b/mobile/apps/photos/lib/ui/tools/free_space_page.dart
@@ -5,13 +5,13 @@ import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:logging/logging.dart';
import "package:photos/generated/l10n.dart";
-import 'package:photos/models/backup_status.dart';
+import 'package:photos/models/freeable_space_info.dart';
import 'package:photos/ui/common/gradient_button.dart';
import "package:photos/ui/notification/toast.dart";
import 'package:photos/utils/delete_file_util.dart';
class FreeSpacePage extends StatefulWidget {
- final BackupStatus status;
+ final FreeableSpaceInfo status;
final bool clearSpaceForFolder;
const FreeSpacePage(
@@ -47,7 +47,7 @@ class _FreeSpacePageState extends State<FreeSpacePage> {
);
}
- Widget _getWidget(BackupStatus status) {
+ Widget _getWidget(FreeableSpaceInfo status) {
final count = status.localIDs.length;
final formattedCount = NumberFormat().format(count);
final String textMessage = widget.clearSpaceForFolder
@@ -172,7 +172,7 @@ class _FreeSpacePageState extends State<FreeSpacePage> {
);
}
- Future<void> _freeStorage(BackupStatus status) async {
+ Future<void> _freeStorage(FreeableSpaceInfo status) async {
bool isSuccess = await deleteLocalFiles(context, status.localIDs);
if (isSuccess == false) {
diff --git a/mobile/apps/photos/lib/ui/viewer/file_details/file_info_face_widget.dart b/mobile/apps/photos/lib/ui/viewer/file_details/file_info_face_widget.dart
index bf0543c60c..6c94084013 100644
--- a/mobile/apps/photos/lib/ui/viewer/file_details/file_info_face_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file_details/file_info_face_widget.dart
@@ -174,8 +174,8 @@ class _FileInfoFaceWidgetState extends State<FileInfoFaceWidget> {
);
return;
}
- final String? clusterID =
- widget.clusterID ?? await mlDataDB.getClusterIDForFaceID(
+ final String? clusterID = widget.clusterID ??
+ await mlDataDB.getClusterIDForFaceID(
widget.face.faceID,
);
if (clusterID != null) {
@@ -208,8 +208,8 @@ class _FileInfoFaceWidgetState extends State<FileInfoFaceWidget> {
.where(
(file) =>
fileIdsToClusterIds[file.uploadedFileID]?.contains(
- clusterID,
- ) ??
+ clusterID,
+ ) ??
false,
)
.toList();
diff --git a/mobile/apps/photos/lib/ui/viewer/file_details/file_info_faces_item_widget.dart b/mobile/apps/photos/lib/ui/viewer/file_details/file_info_faces_item_widget.dart
index 5ccb13fe31..69a6bc1f2f 100644
--- a/mobile/apps/photos/lib/ui/viewer/file_details/file_info_faces_item_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file_details/file_info_faces_item_widget.dart
@@ -486,8 +486,7 @@ class _FacesItemWidgetState extends State<FacesItemWidget> {
? <String, PersonEntity>{}
: await PersonService.instance.getPersonsMap();
- final mlDataDB =
- isOffline ? MLDataDB.offlineInstance : MLDataDB.instance;
+ final mlDataDB = isOffline ? MLDataDB.offlineInstance : MLDataDB.instance;
final faces = await mlDataDB.getFacesForGivenFileID(fileKey);
if (faces == null) {
@@ -507,8 +506,9 @@ class _FacesItemWidgetState extends State<FacesItemWidget> {
final faceIdsToClusterIds = await mlDataDB.getFaceIdsToClusterIds(
faces.map((face) => face.faceID).toList(),
);
- final clusterIDToPerson =
- isOffline ? <String, String>{} : await mlDataDB.getClusterIDToPersonID();
+ final clusterIDToPerson = isOffline
+ ? <String, String>{}
+ : await mlDataDB.getClusterIDToPersonID();
final faceCrops =
await getCachedFaceCrops(widget.file, faces, useTempCache: true);
final defaultFaces = <Face>[];
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart b/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart
index b5e8f2aa23..f63982132c 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart
@@ -21,11 +21,11 @@ import 'package:photos/events/subscription_purchased_event.dart';
import "package:photos/gateways/cast_gw.dart";
import "package:photos/generated/l10n.dart";
import "package:photos/l10n/l10n.dart";
-import 'package:photos/models/backup_status.dart';
import "package:photos/models/button_result.dart";
import 'package:photos/models/collection/collection.dart';
import 'package:photos/models/device_collection.dart';
import "package:photos/models/file/file.dart";
+import 'package:photos/models/freeable_space_info.dart';
import 'package:photos/models/gallery_type.dart';
import "package:photos/models/metadata/common_keys.dart";
import 'package:photos/models/selected_files.dart';
@@ -323,10 +323,10 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
final dialog =
createProgressDialog(context, AppLocalizations.of(context).calculating);
await dialog.show();
- BackupStatus status;
+ FreeableSpaceInfo status;
try {
status = await FilesService.instance
- .getBackupStatus(pathID: widget.deviceCollection!.id);
+ .getFreeableSpaceInfo(pathID: widget.deviceCollection!.id);
} catch (e) {
await dialog.hide();
unawaited(showGenericErrorDialog(context: context, error: e));
@@ -351,7 +351,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
}
}
- void _showSpaceFreedDialog(BackupStatus status) {
+ void _showSpaceFreedDialog(FreeableSpaceInfo status) {
showChoiceDialog(
context,
title: AppLocalizations.of(context).success,
diff --git a/mobile/apps/photos/lib/ui/viewer/people/person_face_widget.dart b/mobile/apps/photos/lib/ui/viewer/people/person_face_widget.dart
index 9af208783f..70fa06b062 100644
--- a/mobile/apps/photos/lib/ui/viewer/people/person_face_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/people/person_face_widget.dart
@@ -266,13 +266,12 @@ class _PersonFaceWidgetState extends State<PersonFaceWidget>
final localIntIds = allFaces
.map((faceID) => getFileIdFromFaceId<int>(faceID))
.toSet();
- final localIdMap = await OfflineFilesDB.instance
- .getLocalIdsForIntIds(localIntIds);
+ final localIdMap =
+ await OfflineFilesDB.instance.getLocalIdsForIntIds(localIntIds);
for (final faceID in allFaces) {
final localIntId = getFileIdFromFaceId<int>(faceID);
final localId = localIdMap[localIntId];
- final candidate =
- localId != null ? localIdToFile[localId] : null;
+ final candidate = localId != null ? localIdToFile[localId] : null;
if (candidate != null) {
fileForFaceCrop = candidate;
fixedFaceID = faceID;
diff --git a/mobile/apps/photos/lib/ui/viewer/search/result/people_section_all_page.dart b/mobile/apps/photos/lib/ui/viewer/search/result/people_section_all_page.dart
index cdb200422a..b9f25ec9f4 100644
--- a/mobile/apps/photos/lib/ui/viewer/search/result/people_section_all_page.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search/result/people_section_all_page.dart
@@ -277,8 +277,7 @@ class SelectablePersonSearchExample extends StatelessWidget {
behavior: HitTestBehavior.translucent,
onTap: () async {
final clusterId =
- searchResult.params[kClusterParamId]
- as String?;
+ searchResult.params[kClusterParamId] as String?;
final result = await showAssignPersonAction(
context,
clusterID: clusterId ?? searchResult.name(),
diff --git a/mobile/apps/photos/lib/ui/viewer/search_tab/people_section.dart b/mobile/apps/photos/lib/ui/viewer/search_tab/people_section.dart
index 9fc3374fe6..942fb47713 100644
--- a/mobile/apps/photos/lib/ui/viewer/search_tab/people_section.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search_tab/people_section.dart
@@ -315,8 +315,7 @@ class PersonSearchExample extends StatelessWidget {
behavior: HitTestBehavior.translucent,
onTap: () async {
final clusterId =
- searchResult.params[kClusterParamId]
- as String?;
+ searchResult.params[kClusterParamId] as String?;
final result = await showAssignPersonAction(
context,
clusterID: clusterId ?? searchResult.name(),
diff --git a/mobile/apps/photos/lib/utils/delete_file_util.dart b/mobile/apps/photos/lib/utils/delete_file_util.dart
index 0779529506..039e895a40 100644
--- a/mobile/apps/photos/lib/utils/delete_file_util.dart
+++ b/mobile/apps/photos/lib/utils/delete_file_util.dart
@@ -15,9 +15,9 @@ import 'package:photos/events/local_photos_updated_event.dart';
import "package:photos/generated/l10n.dart";
import "package:photos/l10n/l10n.dart";
import 'package:photos/models/api/collection/trash_item_request.dart';
-import "package:photos/models/backup_status.dart";
import 'package:photos/models/file/file.dart';
import "package:photos/models/files_split.dart";
+import "package:photos/models/freeable_space_info.dart";
import 'package:photos/models/selected_files.dart';
import "package:photos/service_locator.dart";
import "package:photos/services/files_service.dart";
@@ -375,11 +375,11 @@ Future<bool> deleteLocalFiles(
deletedIDs
.addAll(await _deleteLocalFilesInOneShot(context, localAssetIDs));
}
- // In IOS, the library returns no error and fail to delete any file is
- // there's any shared file. As a stop-gap solution, we initiate deletion in
- // batches. Similar in Android, for large number of files, we have observed
- // that the library fails to delete any file. So, we initiate deletion in
- // batches.
+ // On iOS, PhotoManager.editor.deleteWithIds() silently fails when any
+ // asset in the batch belongs to an iCloud shared album. Shared album
+ // assets are now filtered out before reaching this point, but this
+ // fallback is kept as a safety net. On Android, large file counts can
+ // also cause batch deletion to fail.
if (deletedIDs.isEmpty && Platform.isIOS) {
deletedIDs.addAll(
await _iosDeleteLocalFilesInBatchesFallback(context, localAssetIDs),
@@ -453,11 +453,11 @@ Future<bool> deleteLocalFilesAfterRemovingAlreadyDeletedIDs(
deletedIDs
.addAll(await _deleteLocalFilesInOneShot(context, localAssetIDs));
}
- // In IOS, the library returns no error and fail to delete any file is
- // there's any shared file. As a stop-gap solution, we initiate deletion in
- // batches. Similar in Android, for large number of files, we have observed
- // that the library fails to delete any file. So, we initiate deletion in
- // batches.
+ // On iOS, PhotoManager.editor.deleteWithIds() silently fails when any
+ // asset in the batch belongs to an iCloud shared album. Shared album
+ // assets are now filtered out before reaching this point, but this
+ // fallback is kept as a safety net. On Android, large file counts can
+ // also cause batch deletion to fail.
if (deletedIDs.isEmpty && Platform.isIOS) {
deletedIDs.addAll(
await _iosDeleteLocalFilesInBatchesFallback(context, localAssetIDs),
@@ -510,11 +510,11 @@ Future<bool> retryFreeUpSpaceAfterRemovingAssetsNonExistingInDisk(
);
await LocalSyncService.instance.sync();
- late final BackupStatus status;
+ late final FreeableSpaceInfo status;
final List<String> deletedIDs = [];
final List<String> localAssetIDs = [];
final List<String> localSharedMediaIDs = [];
- status = await FilesService.instance.getBackupStatus();
+ status = await FilesService.instance.getFreeableSpaceInfo();
for (String localID in status.localIDs) {
if (localID.startsWith(sharedMediaIdentifier)) {
@@ -871,27 +871,32 @@ Future<void> showDeleteSheet(
}
}
+// TODO: Remove this fallback once we're confident iCloud shared album
+// files are fully excluded from the free-up-space list. With shared album
+// assets filtered out at the query level, this binary partitioning should
+// no longer be needed β€” the root cause was that PhotoManager.editor.deleteWithIds()
+// silently fails when any asset in the batch belongs to an iCloud shared album.
Future<List<String>> _iosDeleteLocalFilesInBatchesFallback(
BuildContext context,
List<String> localAssetIDs,
) async {
- final List<String> deletedIDs = [];
-
_logger.info(
- "Trying to delete local files in batches",
+ "iOS batch deletion fallback triggered for ${localAssetIDs.length} files",
);
+
+ final List<String> deletedIDs = [];
deletedIDs.addAll(
await _deleteLocalFilesInBatchesRecursively(localAssetIDs, context),
);
if (deletedIDs.isEmpty) {
_logger.warning(
- "Failed to delete local files in recursively batches",
+ "Failed to delete local files in recursive batches",
);
}
- _logger.severe(
- "iOS free-space fallback, deleted ${deletedIDs.length} files with distinct localIDs"
- "in batches}");
+ _logger.info(
+ "iOS free-space fallback, deleted ${deletedIDs.length} files with distinct localIDs in batches",
+ );
return deletedIDs;
}
diff --git a/mobile/apps/photos/lib/utils/ml_util.dart b/mobile/apps/photos/lib/utils/ml_util.dart
index 55bd042a75..75f4a9b915 100644
--- a/mobile/apps/photos/lib/utils/ml_util.dart
+++ b/mobile/apps/photos/lib/utils/ml_util.dart
@@ -30,6 +30,7 @@ import "package:photos/utils/thumbnail_util.dart";
final _logger = Logger("MlUtil");
enum FileDataForML { thumbnailData, fileData }
+
enum MLMode { online, offline }
class IndexStatus {
@@ -236,10 +237,16 @@ Future<List<FileMLInstruction>> getOfflineFilesForMlIndexing() async {
continue;
}
queuedFileIDs.add(localIntId);
- final shouldRunFaces =
- _shouldRunIndexingWithFileId(localIntId, faceIndexedFileIDs, faceMlVersion);
- final shouldRunClip =
- _shouldRunIndexingWithFileId(localIntId, clipIndexedFileIDs, clipMlVersion);
+ final shouldRunFaces = _shouldRunIndexingWithFileId(
+ localIntId,
+ faceIndexedFileIDs,
+ faceMlVersion,
+ );
+ final shouldRunClip = _shouldRunIndexingWithFileId(
+ localIntId,
+ clipIndexedFileIDs,
+ clipMlVersion,
+ );
if (!shouldRunFaces && !shouldRunClip) {
continue;
}
@@ -266,8 +273,7 @@ Stream<List<FileMLInstruction>> fetchEmbeddingsAndInstructions(
if (mode == MLMode.offline) {
final List<FileMLInstruction> filesToIndex =
await getOfflineFilesForMlIndexing();
- final List<List<FileMLInstruction>> chunks =
- filesToIndex.chunks(yieldSize);
+ final List<List<FileMLInstruction>> chunks = filesToIndex.chunks(yieldSize);
for (final batch in chunks) {
yield batch;
}
@@ -420,7 +426,7 @@ Future<int> _getIndexableFileCount({required MLMode mode}) async {
return files
.where(
(file) =>
- (file.localID ?? '').isNotEmpty &&
+ (file.localID ?? '').isNotEmpty &&
(file.uploadedFileID == null || file.uploadedFileID == -1) &&
file.fileType != FileType.other,
)