rails/rails — pull request #10670 by jcoglan (2013-05-17 20:04:04+00:00)
Title: Change find_or_create to do INSERT before SELECT

This makes find_or_create() safe to use with concurrent requests by
relying on unique indexes to raise errors if the INSERT fails. By doing
the SELECT first, we leave this method open to the same race conditions
that affect uniqueness validation.