Skip to content

Commit d13626f

Browse files
authored
[mob][photos] Social (#8616)
## Description Comment and like on photos/videos in shared albums.
2 parents c37d3a7 + 0597982 commit d13626f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+8251
-81
lines changed

mobile/apps/photos/lib/db/files_db.dart

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,56 @@ class FilesDB with SqlDbBase {
587587
return ids;
588588
}
589589

590+
/// Checks which (fileID, collectionID) pairs exist in the database.
591+
///
592+
/// Returns a set of keys in the format "collectionID_fileID" for files that exist.
593+
/// This is more efficient than calling getUploadedFile() for each pair.
594+
Future<Set<String>> getExistingFileKeys(
595+
Set<(int fileID, int collectionID)> pairs,
596+
) async {
597+
if (pairs.isEmpty) return {};
598+
599+
final db = await instance.sqliteAsyncDB;
600+
final existingKeys = <String>{};
601+
602+
// Build a query with OR conditions for each pair
603+
// SQLite has a limit on compound SELECT statements, so we batch
604+
const batchSize = 100;
605+
final pairsList = pairs.toList();
606+
607+
for (var i = 0; i < pairsList.length; i += batchSize) {
608+
final batch = pairsList.sublist(
609+
i,
610+
i + batchSize > pairsList.length ? pairsList.length : i + batchSize,
611+
);
612+
613+
final conditions = batch
614+
.map(
615+
(_) => '($columnUploadedFileID = ? AND $columnCollectionID = ?)',
616+
)
617+
.join(' OR ');
618+
619+
final args = <Object>[];
620+
for (final (fileID, collectionID) in batch) {
621+
args.add(fileID);
622+
args.add(collectionID);
623+
}
624+
625+
final results = await db.getAll(
626+
'SELECT $columnUploadedFileID, $columnCollectionID FROM $filesTable WHERE $conditions',
627+
args,
628+
);
629+
630+
for (final row in results) {
631+
final fileID = row[columnUploadedFileID] as int;
632+
final collectionID = row[columnCollectionID] as int;
633+
existingKeys.add('${collectionID}_$fileID');
634+
}
635+
}
636+
637+
return existingKeys;
638+
}
639+
590640
Future<(Set<int>, Map<String, int>)> getUploadAndHash(
591641
int collectionID,
592642
) async {

0 commit comments

Comments
 (0)