Avoid group-sync deadlock by making post-upload save async

// FREEBIE
pull/1/head
Michael Kirk 8 years ago
parent 98fd15fae7
commit 8ef9e96b91

@ -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,9 +81,10 @@
+ (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 shared readWrite connection.
*/ */
- (void)save; - (void)save;
- (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