Re: Avoiding duplicate records
Re: Avoiding duplicate records
- Subject: Re: Avoiding duplicate records
- From: Chuck Hill <email@hidden>
- Date: Tue, 22 Jan 2008 10:45:45 -0800
On Jan 15, 2008, at 7:19 AM, Mike Schrag wrote:
1) Fo a fetch request to get the contacts with the emails of the
100 contacts batch (ie, blablabla where email = email1 or email =
email2 or email = email3 ...).
2) Remove duplicates in memory using a fast method, like putting
the stuff in NSSets or whatever.
3) Try to save again. Of course, it may still fail (concurrency
sucks) but the probability is much lower.
This is all thought with the assumption that the UNIQUE-related
exception is thrown when the first offending object is inserted,
so I won't get all the information I need in one single exception,
which I'm not 100% sure it's true yet.
Depending on how your unique constraint is configured, it may throw
when the first conflicting insert happens or at the end of the
commit (this is that deferrable initially deferred, thing, which
I've honestly never tried on a unique constraint, but presumably it
works the same).
Yes. If the constraint is immediate, you get an exception and can
extract the EO that the constraint failed on. This is a good place
to use an immediate constraint if you can get away with it (e.g. if
EOF's Random Operation Ordering is not tripping you up). If the
constraint is deferred, you don't get that information.
Chuck
The only thing I would consider is how frequent conflicts will be.
If conflicts will be frequent, it may be cheaper to fetch dupes
first to weed them out (so you're not constantly failing out 100-
insert blocks).
I think if I were in your position I would just benchmark:
1) committing one at a time -- this is logically the easiest, but
it may be the overhead for this is way high ... but WO doesn't do
batching inserts ANYWAY, so who knows
2) fetching 100, comparing, deduping, then inserting and committing
3) inserting 100, committing, catch exception (fetch 100,
comparing, deduping, inserting, rinse and repeat)
You might also just benchmark the fetching and the inserting
independently so you know the relative cost of 100 of each for your
average data.
--
Practical WebObjects - for developers who want to increase their
overall knowledge of WebObjects or who are trying to solve specific
problems.
http://www.global-village.net/products/practical_webobjects
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden