Skip to content

Commit cbd22e6

Browse files
lissine0tmolitor-stud-tu
authored andcommitted
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.
1 parent c25d95c commit cbd22e6

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Monal/Classes/DataLayerMigrations.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ WHEN EXISTS ( \
10551055

10561056
//make sure all muc messages in our history db have an occupant id
10571057
[self updateDB:db withDataLayer:dataLayer toVersion:7.006 withBlock:^{
1058-
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);"];
10591059
DDLogWarn(@"History IDs of messages with missing occupant IDs during DB migration: %@", missingOccupantIds);
10601060
for(NSNumber* historyId in missingOccupantIds)
10611061
[db executeNonQuery:@"UPDATE message_history SET occupant_id=? WHERE message_history_id=?;" andArguments:@[[[NSUUID UUID] UUIDString], historyId]];

0 commit comments

Comments
 (0)