基本上我发现所有“first_or_initialize”/“first_or_create”调用都有竞争条件。
server1: first_or_initialize -> initialize
server1: save new record
server2: first_or_initialize -> first
server2: update old record
server1: first_or_initialize -> initialize
server2: first_or_initialize -> initialize
server1: save new record
server2: save new record **ERROR: duplicate key violates unique constraint**
我该如何解决?