Skip to content

Commit

Permalink
Merge pull request #2217 from cfis/concurrency
Browse files Browse the repository at this point in the history
Concurrency Fixes
  • Loading branch information
segiddins committed May 15, 2015
2 parents 53ba779 + 4d3c8e1 commit 45aee26
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions Code/CoreData/RKRelationshipConnectionOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,14 @@ - (id)findConnectedValueForConnection:(RKConnectionDescription *)connection shou
{
*shouldConnectRelationship = YES;
id connectionResult = nil;
if (connection.sourcePredicate && ![connection.sourcePredicate evaluateWithObject:self.managedObject]) return nil;
if (connection.sourcePredicate) {
__block BOOL evaluationResult;
[self.managedObject.managedObjectContext performBlockAndWait:^{
evaluationResult = [connection.sourcePredicate evaluateWithObject:self.managedObject];
}];

if (!evaluationResult) return nil;
}

if ([connection isForeignKeyConnection]) {
NSDictionary *attributeValues = RKConnectionAttributeValuesWithObject(connection, self.managedObject);
Expand All @@ -157,11 +164,15 @@ - (id)findConnectedValueForConnection:(RKConnectionDescription *)connection shou
*shouldConnectRelationship = NO;
return nil;
}
NSSet *managedObjects = [self.managedObjectCache managedObjectsWithEntity:[connection.relationship destinationEntity]
attributeValues:attributeValues
inManagedObjectContext:self.managedObjectContext];
if (connection.destinationPredicate) managedObjects = [managedObjects filteredSetUsingPredicate:connection.destinationPredicate];
if (!connection.includesSubentities) managedObjects = [managedObjects filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"entity == %@", [connection.relationship destinationEntity]]];
__block NSSet *managedObjects = [self.managedObjectCache managedObjectsWithEntity:[connection.relationship destinationEntity]
attributeValues:attributeValues
inManagedObjectContext:self.managedObjectContext];

[self.managedObjectContext performBlockAndWait:^{
if (connection.destinationPredicate) managedObjects = [managedObjects filteredSetUsingPredicate:connection.destinationPredicate];
if (!connection.includesSubentities) managedObjects = [managedObjects filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"entity == %@", [connection.relationship destinationEntity]]];
}];

if ([connection.relationship isToMany]) {
connectionResult = managedObjects;
} else {
Expand Down

0 comments on commit 45aee26

Please sign in to comment.