Try to avoid 500s caused by database race conditions#5341
Conversation
zachmargolis
left a comment
There was a problem hiding this comment.
LGTM!!! I can't believe these are not the same method 🤦
Might be worth adding a lint/cop for to help us do the right thing?
ec59d13 to
b36974c
Compare
I was hoping the same, but the confounder right now is |
🤦 whoops, just realized neither of the indexes are unique my b |
find_or_create_byis subject to race conditions if a unique query runs more than one at a timecreate_or_find_byflips it so it attempts to create first, and if a unique constraint database exception occurs, it then does a select to get that row.Example New Relic error