I’m wondering if there is a good Rails solution to avoiding duplicate
inserts with identical content. I know of the locking to prevent
updates, but looking for something on inserts.
For example, say you have an API to a blog system that lets a caller
post a comment. The client calls “addComment” with the same parameters
(say, user_id and comment) twice and each request is handled by a
different mongrel instance. How can the duplicate comment be prevented
from being saved? They would be different rows, and I would like to
avoid table locking. (In this example, the client can’t be controlled,
so it needs to be server-side.)
I believe that a validating on before_save is not enough because there
would still be a window between the validation completing and writing
the row since it is only the row that is locked.
Any suggestions would be appreciated.