You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix the db migration that adds occupantIDs to messages that don't have them
In SQL, comparing with `NULL` is done using `IS`, not `=`
And while at it, replace the SELECT query with a faster one by removing the join.
On my database, the SELECT with the join took 110ms, whereas the new one took 33ms.
NSArray<NSNumber*>* missingOccupantIds = [db executeScalarReader:@"SELECT message_history_id FROM message_history AS M WHERE (occupant_id = NULL OR occupant_id = '') AND EXISTS(SELECT 1 FROM buddylist AS B WHERE M.account_id = B.account_id AND M.buddy_name = B.buddy_name AND B.Muc);"];
1058
+
NSArray<NSNumber*>* missingOccupantIds = [db executeScalarReader:@"SELECT message_history_id FROM message_history WHERE (occupant_id IS NULL OR occupant_id = '') AND buddy_name IN (SELECT buddy_name FROM buddylist WHERE Muc=1);"];
1059
1059
DDLogWarn(@"History IDs of messages with missing occupant IDs during DB migration: %@", missingOccupantIds);
1060
1060
for(NSNumber* historyId in missingOccupantIds)
1061
1061
[db executeNonQuery:@"UPDATE message_history SET occupant_id=? WHERE message_history_id=?;"andArguments:@[[[NSUUIDUUID] UUIDString], historyId]];
0 commit comments