• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
coredata and loooooooooooooooong waits
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

coredata and loooooooooooooooong waits


  • Subject: coredata and loooooooooooooooong waits
  • From: Benjamin Salanki <email@hidden>
  • Date: Tue, 17 Oct 2006 10:00:23 +0200

Hi, I have a problem with coredata fetches. The problem is strange, since I can't reproduce them myself, but a few beta testers contact me that my app sometimes taes 5-25 seconds to complete a task. Narrowing down the problem using extensive loging (the bet testers just hated all the lines in the console prointout :D) I found that the problem is in a method I called arrangedObjectsForStore.

My data model contains two entities, one is called a store and the other is an item. A store can have multiple items using a one-to-many relationship, and there's a reverse relationship so I can always tell from an item which store it is assigned to.

The code is as follows:

- (NSArray*)arrangedObjectsForStore:(NSManagedObject*)store
{
	NSManagedObjectContext * moc = [[NSApp delegate] managedObjectContext];
	NSEntityDescription * entityDescription = [NSEntityDescription entityForName:@"storeEntity" inManagedObjectContext:moc];
	NSFetchRequest * request = [[[NSFetchRequest alloc] init] autorelease];
	[request setEntity:entityDescription];
	NSPredicate *predicate = [NSPredicate predicateWithFormat:@"storeID = %d", [[store valueForKeyPath:@"storeID"] intValue]];
	[request setPredicate:predicate];
	NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"storeID" ascending:NO];
	[request setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]];
	[sortDescriptor release];

	NSArray* result = [moc executeFetchRequest:request error:nil];

	result = [[[result objectAtIndex:0] valueForKeyPath:@"storeClips"] allObjects];

	result = [result sortedArrayUsingDescriptors:[NSArray arrayWithObject:[[[NSSortDescriptor alloc] initWithKey:@"clipID" ascending:NO] autorelease]]];

	return result;
}

Now judging from the logs this can take anywhere from 5-25 seconds to return, and the number of stores is less than 5, the items per store are limited to 1000. I don't really think it should take this long to return. Also, once fetched, the next time it will be almost instantaneous until I add a new item to the context, then it again takes 5-25 seconds to return.

And this happens on both a dual G4 and a core duo iMac - at least that's the machines the beta testers reported problems with.

Am I doing something wrong in my fetch request? How can I speed things up? SHould this really be happening?

THanks for any hints to the right direction.

Ben
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: coredata and loooooooooooooooong waits
      • From: Jakob Olesen <email@hidden>
  • Prev by Date: Do something when an NSTextView gains focus
  • Next by Date: keypress events + responder chain
  • Previous by thread: Re: Do something when an NSTextView gains focus
  • Next by thread: Re: coredata and loooooooooooooooong waits
  • Index(es):
    • Date
    • Thread