Skip to content

armgit / ente

Public Imported from GitHub
0

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

refactor(photos): clarify latest comment query scope

ashilkneecf8af97772
diff --git a/mobile/apps/photos/lib/db/social_db.dart b/mobile/apps/photos/lib/db/social_db.dart
index acfb9d0aea..4ef36cf6b0 100644
--- a/mobile/apps/photos/lib/db/social_db.dart
+++ b/mobile/apps/photos/lib/db/social_db.dart
@@ -153,22 +153,27 @@ class SocialDB {
return rows.map(_rowToComment).toList();
}
+ /// Restricts the lookup to [candidateCollectionIDs] so the composite
+ /// file/collection index can narrow the rows considered for the latest item.
Future<Comment?> getLatestCommentForFile(
int fileID, {
- required List<int> collectionIDs,
+ required List<int> candidateCollectionIDs,
}) async {
- if (collectionIDs.isEmpty) {
+ if (candidateCollectionIDs.isEmpty) {
return null;
}
- final placeholders = List.filled(collectionIDs.length, '?').join(',');
+ final placeholders = List.filled(
+ candidateCollectionIDs.length,
+ '?',
+ ).join(',');
final db = await database;
final rows = await db.query(
_commentsTable,
where:
'file_id = ? AND is_deleted = 0 '
'AND collection_id IN ($placeholders)',
- whereArgs: [fileID, ...collectionIDs],
+ whereArgs: [fileID, ...candidateCollectionIDs],
orderBy: 'created_at DESC',
limit: 1,
);
diff --git a/mobile/apps/photos/lib/models/social/social_data_provider.dart b/mobile/apps/photos/lib/models/social/social_data_provider.dart
index b2cc58d7bf..b551dc04f0 100644
--- a/mobile/apps/photos/lib/models/social/social_data_provider.dart
+++ b/mobile/apps/photos/lib/models/social/social_data_provider.dart
@@ -24,11 +24,16 @@ class SocialDataProvider {
return _db.getCommentsForFile(fileID);
}
+ /// [candidateCollectionIDs] narrows the indexed lookup to collections the
+ /// caller already knows are eligible.
Future<Comment?> getLatestCommentForFile(
int fileID, {
- required List<int> collectionIDs,
+ required List<int> candidateCollectionIDs,
}) {
- return _db.getLatestCommentForFile(fileID, collectionIDs: collectionIDs);
+ return _db.getLatestCommentForFile(
+ fileID,
+ candidateCollectionIDs: candidateCollectionIDs,
+ );
}
Future<int> getCommentCountForFile(int fileID) {
diff --git a/mobile/apps/photos/lib/ui/social/widgets/file_social_overlay.dart b/mobile/apps/photos/lib/ui/social/widgets/file_social_overlay.dart
index c9aa8b0c0b..f3b6321d0f 100644
--- a/mobile/apps/photos/lib/ui/social/widgets/file_social_overlay.dart
+++ b/mobile/apps/photos/lib/ui/social/widgets/file_social_overlay.dart
@@ -140,7 +140,10 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {
final results = await Future.wait<Object?>([
provider.getReactionsForFile(fileID),
provider.getCommentCountForFile(fileID),
- provider.getLatestCommentForFile(fileID, collectionIDs: collectionIDs),
+ provider.getLatestCommentForFile(
+ fileID,
+ candidateCollectionIDs: collectionIDs,
+ ),
]);
if (!_isCurrentLoad(fileID, generation)) return;