π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][locker] Count collection files with a database query (#13579)
aman-pilot60b66d1a5087
diff --git a/mobile/apps/locker/changes/collection-file-count.md b/mobile/apps/locker/changes/collection-file-count.mdnew file mode 100644index 0000000000..6c6ff2ed10--- /dev/null+++ b/mobile/apps/locker/changes/collection-file-count.md@@ -0,0 +1 @@+- Improved performance when counting files in collections.diff --git a/mobile/apps/locker/lib/services/collections/collections_service.dart b/mobile/apps/locker/lib/services/collections/collections_service.dartindex eceee2cd47..f44ca4c36c 100644--- a/mobile/apps/locker/lib/services/collections/collections_service.dart+++ b/mobile/apps/locker/lib/services/collections/collections_service.dart@@ -254,10 +254,8 @@ class CollectionService {}}- Future<int> getFileCount(Collection collection) async {- final files = await getFilesInCollection(collection);- return files.length;- }+ Future<int> getFileCount(Collection collection) async =>+ _db.getFileCount(collection);Future<int> getFileSize(EnteFile file) async {int fileSize;diff --git a/mobile/apps/locker/lib/services/db/locker_db.dart b/mobile/apps/locker/lib/services/db/locker_db.dartindex 176b22c6a5..5b19ab1080 100644--- a/mobile/apps/locker/lib/services/db/locker_db.dart+++ b/mobile/apps/locker/lib/services/db/locker_db.dart@@ -451,6 +451,19 @@ class LockerDB extends EnteBaseDatabase {await batch.commit();}+ Future<int> getFileCount(Collection collection) async {+ final result = await _db.rawQuery(+ '''+ SELECT COUNT(DISTINCT f.uploaded_file_id)+ FROM $_filesTable f+ INNER JOIN $_collectionFilesTable cf ON f.uploaded_file_id = cf.uploaded_file_id+ WHERE cf.collection_id = ?+ ''',+ [collection.id],+ );+ return Sqflite.firstIntValue(result) ?? 0;+ }+Future<List<EnteFile>> getFilesInCollection(Collection collection) async {final result = await _db.rawQuery('''