Skip to content

armgit / ente

Public Imported from GitHub
0

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

Resolve parent_comment_user_id via post-sync SQL lookup

ashilkne56139e6e305
diff --git a/mobile/apps/photos/lib/db/social_db.dart b/mobile/apps/photos/lib/db/social_db.dart
index ec2ea9c7c6..8cc7010591 100644
--- a/mobile/apps/photos/lib/db/social_db.dart
+++ b/mobile/apps/photos/lib/db/social_db.dart
@@ -409,6 +409,25 @@ class SocialDB {
await batch.commit(noResult: true);
}
+ /// Resolves `parent_comment_user_id` for reply comments by looking up the
+ /// parent comment's `user_id`. Only processes rows where the field is still
+ /// NULL, making it idempotent.
+ Future<void> resolveParentCommentUserIDs(int collectionID) async {
+ final db = await database;
+ await db.rawUpdate(
+ '''
+ UPDATE $_commentsTable SET parent_comment_user_id = (
+ SELECT c2.user_id FROM $_commentsTable c2
+ WHERE c2.id = $_commentsTable.parent_comment_id
+ )
+ WHERE collection_id = ?
+ AND parent_comment_id IS NOT NULL
+ AND parent_comment_user_id IS NULL
+ ''',
+ [collectionID],
+ );
+ }
+
Future<void> upsertReactions(List<Reaction> reactions) async {
if (reactions.isEmpty) return;
final db = await database;
diff --git a/mobile/apps/photos/lib/services/social_sync_service.dart b/mobile/apps/photos/lib/services/social_sync_service.dart
index f8b7ad7de8..012650c8ad 100644
--- a/mobile/apps/photos/lib/services/social_sync_service.dart
+++ b/mobile/apps/photos/lib/services/social_sync_service.dart
@@ -96,6 +96,8 @@ class SocialSyncService {
await _db.getReactionsSyncTime(collectionID)) {
await _db.setReactionsSyncTime(collectionID, maxReactionsUpdatedAt);
}
+
+ await _db.resolveParentCommentUserIDs(collectionID);
} catch (e) {
_logger.severe('Failed to sync collection $collectionID', e);
rethrow;
@@ -143,6 +145,8 @@ class SocialSyncService {
final reactions = _decryptReactions(response.reactions, collectionID);
await _db.upsertReactions(reactions);
}
+
+ await _db.resolveParentCommentUserIDs(collectionID);
} catch (e) {
_logger.warning('Failed to sync social data for file $fileID', e);
// Don't rethrow - this is a non-critical operation