Address deadlocks in profile manager.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent cb365d0a58
commit 57b5ccdc3f

@ -813,23 +813,7 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640;
{ {
OWSAssert(recipientId.length > 0); OWSAssert(recipientId.length > 0);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [self addUsersToProfileWhitelist:@[ recipientId ]];
@synchronized(self)
{
if ([self isUserInProfileWhitelist:recipientId]) {
return;
}
self.userProfileWhitelistCache[recipientId] = @(YES);
[self.dbConnection setBool:YES forKey:recipientId inCollection:kOWSProfileManager_UserWhitelistCollection];
}
[[NSNotificationCenter defaultCenter] postNotificationNameAsync:kNSNotificationName_ProfileWhitelistDidChange
object:nil
userInfo:@{
kNSNotificationKey_ProfileRecipientId : recipientId,
}];
});
} }
- (void)addUsersToProfileWhitelist:(NSArray<NSString *> *)recipientIds - (void)addUsersToProfileWhitelist:(NSArray<NSString *> *)recipientIds
@ -851,15 +835,18 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640;
return; return;
} }
for (NSString *recipientId in recipientIds) {
self.userProfileWhitelistCache[recipientId] = @(YES);
}
}
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { [self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
for (NSString *recipientId in recipientIds) { for (NSString *recipientId in recipientIds) {
[transaction setObject:@(YES) [transaction setObject:@(YES)
forKey:recipientId forKey:recipientId
inCollection:kOWSProfileManager_UserWhitelistCollection]; inCollection:kOWSProfileManager_UserWhitelistCollection];
self.userProfileWhitelistCache[recipientId] = @(YES);
} }
}]; }];
}
for (NSString *recipientId in newRecipientIds) { for (NSString *recipientId in newRecipientIds) {
[[NSNotificationCenter defaultCenter] [[NSNotificationCenter defaultCenter]
@ -895,24 +882,24 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640;
OWSAssert(groupId.length > 0); OWSAssert(groupId.length > 0);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
@synchronized(self)
{
NSString *groupIdKey = [groupId hexadecimalString]; NSString *groupIdKey = [groupId hexadecimalString];
@synchronized(self)
{
if ([self isGroupIdInProfileWhitelist:groupId]) { if ([self isGroupIdInProfileWhitelist:groupId]) {
return; return;
} }
[self.dbConnection setBool:YES forKey:groupIdKey inCollection:kOWSProfileManager_GroupWhitelistCollection];
self.groupProfileWhitelistCache[groupIdKey] = @(YES); self.groupProfileWhitelistCache[groupIdKey] = @(YES);
}
[[NSNotificationCenter defaultCenter] [self.dbConnection setBool:YES forKey:groupIdKey inCollection:kOWSProfileManager_GroupWhitelistCollection];
postNotificationNameAsync:kNSNotificationName_ProfileWhitelistDidChange
[[NSNotificationCenter defaultCenter] postNotificationNameAsync:kNSNotificationName_ProfileWhitelistDidChange
object:nil object:nil
userInfo:@{ userInfo:@{
kNSNotificationKey_ProfileGroupId : groupId, kNSNotificationKey_ProfileGroupId : groupId,
}]; }];
}
}); });
} }

Loading…
Cancel
Save