[Rails] Re: rescuing ActiveRecord::RecordNotUnique: clever or ugly?
Let me redact that previous post...my only excuse is that I hadn't had
my coffee yet!
If the time to make a DB query (let's call it 1 Unit of time) swamps out
any amount of processing in Ruby, then:
Approach A (do a SELECT to check for existence of the record before
attempting an insert) will take 1 Unit if the record exists and 2 Units
if the record does not exist.
Approach B (always attempt the insert, let the DB signal an error,
recover by doing a SELECT) will take 2 Units if the record exists and 1
Unit if the record does not exist.
So I'd conclude that:
If the chance of a duplicate insert is less than 50%, you're better off
with Approach B, otherwise you should choose Approach A.
Yes?
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home