Re: CoreData: Preventing fault firing
Re: CoreData: Preventing fault firing
- Subject: Re: CoreData: Preventing fault firing
- From: Brad Miller <email@hidden>
- Date: Tue, 24 Jul 2007 20:17:02 -0700
On Jul 23, 2007, at 11:18 PM, Chris Ridd wrote:
On 24/7/07 5:17, "Brad Miller" <email@hidden> wrote:
Hi,
Is there anyway to prevent an object from firing faults? I've run
into a fairly big slowdown in my app due to relationships being
fetched that don't need to be. In my case I have a background
operation that fetches a group of objects, sets an int value in them,
and then terminates. When I set the value, the 4 many-to-many
relationships that the object has are each being fired in separate
sql queries which according to the sql logging adds about .0016 sec.
The operation could be over a few thousand objects, so that time adds
up quick.
The function that's running looks like (pseudo code here to keep it
short):
- (void)updateObjects
{
NSArray *objects = results from a fetch request
foreach(object in objects)
[object setValue:[NSNumber numberWithInt:1] forKey:@"theKey"];
}
I've confirmed that the faults are being fired when the serValue is
executed by adding logging around the call. There is no UI for the
operation that might be triggering them either.
The top hit returned by searching developer.apple.com for "core
data bulk"
looks potentially useful:
<http://developer.apple.com/documentation/Cocoa/Conceptual/
ModelObjects/Arti
cles/moIntegrating.html>
Thanks for the suggestion Chris. Unfortunately that's for updating
multiple objects in a to-many relationship. I'm trying to change a
single, simple value in multiple objects without faults being fired
on relationships that aren't being touched.
On a suggestion Adam sent me, I tried implementing a setter for the
value:
- (void)setState:(NSNumber*)value_ {
[self willChangeValueForKey:@"state"];
[self setPrimitiveValue:value_ forKey:@"state"];
[self didChangeValueForKey:@"state"];
}
I'm still getting the issue, but it showed that the
willChangeValueForKey: call is the culprit in firing the faults.
The only solution I can come up with right now is to pre-fetch all of
those relationships. It won't solve the problem, but should mask it
a little since all of the relationships will be fetched in one query
instead of 5 queries for each object.
It's times like this that I wish I could simply write an update sql
query to run. =)
Brad
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden