Is your topic node self-referential? Maybe CoreData doesn't prefetch
circular references.

-Heath Borders
heath.bord...@gmail.com
Twitter: heathborders
http://heath-tech.blogspot.com



On Tue, Jul 19, 2011 at 12:21 AM, Gideon King <gid...@novamind.com> wrote:
> Hi, I'm doing a fetch of some objects like this:
>
> entity = [NSEntityDescription entityForName:kNMTopicNodeEntityKey 
> inManagedObjectContext:[self managedObjectContext]];
> request = [[NSFetchRequest alloc] init];
> [request setEntity:entity];
> [request setRelationshipKeyPathsForPrefetching:[NSArray 
> arrayWithObjects:@"topic",@"view", nil]];
>
> results = [[self managedObjectContext] executeFetchRequest:request 
> error:&error];
> if (results) {
>        log4Debug(@"Loaded %d topic nodes", [results count])
> }
> [request release];
>
>
> The log tells me id loaded my 2,000 topics.
>
> Then later, I do the following:
>
> // This is an array of topic nodes - the things that I have just fetched
> NSArray *allTopics = [map.rootTopicNode allDescendantTopicNodesIncludingSelf];
>
> NSSortDescriptor *sd = nil;
> if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_5) {
>        sd = [NSSortDescriptor sortDescriptorWithKey:@"view.zIndex" 
> ascending:YES];
> } else {
>        sd = [[[NSSortDescriptor alloc] initWithKey:@"view.zIndex" 
> ascending:YES] autorelease];
> }
>
> for (NMTopicNodeMO *node in [allTopics sortedArrayUsingDescriptors:[NSArray 
> arrayWithObject:sd]]) {
>        Do stuff....
> }
>
>
> But this was running really slowly, so I commented out the above couple of 
> lines, and did the following check:
>
> for (NMTopicNodeMO *ttn in allTopics) {
>        if ([ttn isFault]) {
>                log4Debug(@"Node is a fault");
>        }
>        if ([ttn.view isFault]) {
>                log4Debug(@"View is fault");
>        }
> }
>
> ...and it told me that the view was a fault for every topic node (but none of 
> the topic nodes were faults)!
>
> But I told it to pre-fetch the view relationship. Any ideas why it wouldn't 
> work?
>
>
>
> TIA
>
> Gideon
>
>
>
>
>
>
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/heath.borders%40gmail.com
>
> This email sent to heath.bord...@gmail.com
>
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to