Re: Unique items in Core Data models
Re: Unique items in Core Data models
- Subject: Re: Unique items in Core Data models
- From: Paulo F.Andrade <email@hidden>
- Date: Fri, 18 May 2007 13:28:55 +0100
Of course, I would also have to pass the NSManagedObjectContext to
the "createServer" class method.
Paulo F. Andrade 52439@IST
mailto: email@hidden
On 2007/05/18, at 13:22, Paulo F. Andrade wrote:
Just my 2 cents.
See below.
Paulo F. Andrade 52439@IST
mailto: email@hidden
On 2007/05/15, at 22:59, mmalc crawford wrote:
On May 15, 2007, at 2:52 PM, mmalc crawford wrote:
But that still leaves the issue of determining uniqueness of a
Title :-)
Sorry, I pressed Deliver by accident...
As noted in a previous post, the naive technique for determining
the uniqueness of a given attribute (for example, a Title's title)
is to simply execute a fetch with a predicate for
<uniquedAttributeName> = <value> and check that the returned array
has a count of 0. This is, however, potentially very expensive.
I'm doing this, and it __is__ very expensive. Example: starting
with an empty database I insert about 1800 servers whose addresses
must be unique, it starts out fast (empry database) but becomes
painfully slow.
If you're creating several unique values at the same time, the
first thing to do would be to combine all the values into a single
fetch.
Better still, though, maintain an application-global dictionary of
existing unique values. The key can be the uniqued value, the
corresponding value in the dictionary is the objectID of the
corresponding managed object (you can use the objectID in any
managed object context...). Thus rather than executing a fetch,
you check the local cache.
This was also my idea. I'm still no sure how to do this because I
have different context's on different threads. I was thinking of
sharedServerFactory object that would maintain that cache and
create the server objects...
Hmmm.. actually, maybe it would be even simpler to have a class
method on my Server entity named "createServerWithAddress:" and
maintain a static NSDictionary in that method.
Chris may have more to say about this pattern...
mmalc
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
40mega.ist.utl.pt
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
40mega.ist.utl.pt
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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