Merge branch 'mkirk/group-sync-deadlock' into release/2.18.1

pull/1/head
Michael Kirk 8 years ago
commit bdc43ac112

@ -1,12 +1,16 @@
// Copyright © 2016 Open Whisper Systems. All rights reserved. //
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "OWSOutgoingSyncMessage.h" #import "OWSOutgoingSyncMessage.h"
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@class YapDatabaseReadTransaction;
@interface OWSSyncGroupsMessage : OWSOutgoingSyncMessage @interface OWSSyncGroupsMessage : OWSOutgoingSyncMessage
- (NSData *)buildPlainTextAttachmentData; - (NSData *)buildPlainTextAttachmentDataWithTransaction:(YapDatabaseReadTransaction *)transaction;
@end @end

@ -40,7 +40,7 @@ NS_ASSUME_NONNULL_BEGIN
return syncMessageBuilder; return syncMessageBuilder;
} }
- (NSData *)buildPlainTextAttachmentData - (NSData *)buildPlainTextAttachmentDataWithTransaction:(YapDatabaseReadTransaction *)transaction
{ {
// TODO use temp file stream to avoid loading everything into memory at once // TODO use temp file stream to avoid loading everything into memory at once
// First though, we need to re-engineer our attachment process to accept streams (encrypting with stream, // First though, we need to re-engineer our attachment process to accept streams (encrypting with stream,
@ -49,14 +49,16 @@ NS_ASSUME_NONNULL_BEGIN
[dataOutputStream open]; [dataOutputStream open];
OWSGroupsOutputStream *groupsOutputStream = [OWSGroupsOutputStream streamWithOutputStream:dataOutputStream]; OWSGroupsOutputStream *groupsOutputStream = [OWSGroupsOutputStream streamWithOutputStream:dataOutputStream];
[TSGroupThread enumerateCollectionObjectsUsingBlock:^(id obj, BOOL *stop) { [TSGroupThread
if (![obj isKindOfClass:[TSGroupThread class]]) { enumerateCollectionObjectsWithTransaction:transaction
DDLogVerbose(@"Ignoring non group thread in thread collection: %@", obj); usingBlock:^(id obj, BOOL *stop) {
return; if (![obj isKindOfClass:[TSGroupThread class]]) {
} DDLogVerbose(@"Ignoring non group thread in thread collection: %@", obj);
TSGroupModel *group = ((TSGroupThread *)obj).groupModel; return;
[groupsOutputStream writeGroup:group]; }
}]; TSGroupModel *group = ((TSGroupThread *)obj).groupModel;
[groupsOutputStream writeGroup:group];
}];
[groupsOutputStream flush]; [groupsOutputStream flush];
[dataOutputStream close]; [dataOutputStream close];

@ -615,8 +615,8 @@ NS_ASSUME_NONNULL_BEGIN
}]; }];
} else if (syncMessage.request.type == OWSSignalServiceProtosSyncMessageRequestTypeGroups) { } else if (syncMessage.request.type == OWSSignalServiceProtosSyncMessageRequestTypeGroups) {
OWSSyncGroupsMessage *syncGroupsMessage = [[OWSSyncGroupsMessage alloc] init]; OWSSyncGroupsMessage *syncGroupsMessage = [[OWSSyncGroupsMessage alloc] init];
DataSource *dataSource = DataSource *dataSource = [DataSourceValue
[DataSourceValue dataSourceWithSyncMessage:[syncGroupsMessage buildPlainTextAttachmentData]]; dataSourceWithSyncMessage:[syncGroupsMessage buildPlainTextAttachmentDataWithTransaction:transaction]];
[self.messageSender sendTemporaryAttachmentData:dataSource [self.messageSender sendTemporaryAttachmentData:dataSource
contentType:OWSMimeTypeApplicationOctetStream contentType:OWSMimeTypeApplicationOctetStream
inMessage:syncGroupsMessage inMessage:syncGroupsMessage

@ -107,9 +107,7 @@ static const CGFloat kAttachmentUploadProgressTheta = 0.001f;
DDLogInfo(@"%@ Uploaded attachment: %p.", self.tag, attachmentStream); DDLogInfo(@"%@ Uploaded attachment: %p.", self.tag, attachmentStream);
attachmentStream.serverId = serverId; attachmentStream.serverId = serverId;
attachmentStream.isUploaded = YES; attachmentStream.isUploaded = YES;
[attachmentStream save]; [attachmentStream saveAsyncWithCompletionBlock:successHandlerWrapper];
successHandlerWrapper();
} }
failure:failureHandlerWrapper]; failure:failureHandlerWrapper];

@ -81,10 +81,22 @@
+ (instancetype)fetchObjectWithUniqueID:(NSString *)uniqueID NS_SWIFT_NAME(fetch(uniqueId:)); + (instancetype)fetchObjectWithUniqueID:(NSString *)uniqueID NS_SWIFT_NAME(fetch(uniqueId:));
/** /**
* Saves the object with a new YapDatabaseConnection * Saves the object with the shared readWrite connection.
*
* This method will block if another readWrite transaction is open.
*/ */
- (void)save; - (void)save;
/**
* Saves the object with the shared readWrite connection - does not block.
*
* Be mindful that this method may clobber other changes persisted
* while waiting to open the readWrite transaction.
*
* @param completionBlock is called on the main thread
*/
- (void)saveAsyncWithCompletionBlock:(void (^_Nullable)(void))completionBlock;
/** /**
* Saves the object with the provided transaction * Saves the object with the provided transaction
* *

@ -37,6 +37,14 @@
}]; }];
} }
- (void)saveAsyncWithCompletionBlock:(void (^_Nullable)(void))completionBlock
{
[[self dbReadWriteConnection] asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
[self saveWithTransaction:transaction];
}
completionBlock:completionBlock];
}
- (void)touchWithTransaction:(YapDatabaseReadWriteTransaction *)transaction - (void)touchWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
[transaction touchObjectForKey:self.uniqueId inCollection:[self.class collection]]; [transaction touchObjectForKey:self.uniqueId inCollection:[self.class collection]];

Loading…
Cancel
Save