0
如果我们并行发送两个请求,一个进程的db更新对其他进程是不可见的。实际上,我们正在上传带有一些数据的文件,并且在特定属性上有独特的检查(不在模型或数据库级别,由某些业务规则控制)。Rails两个进程无法看到对方db更新
Process 1:
foo1 = Foo.new(data from file)
foo1.number = 1 # from file
foo1.save
foo1.process # it will only get processed if there is no other Foo with same number i.e. 1
Process 2:
foo2 = Foo.new(data from file)
foo2.number = 1 # some other user has uploaded the file with same number
foo2.save
foo2.process # it will only get processed if there is no other Foo with same number i.e. 1
我如何处理这种情况,这样我可以让一个完整的过程,使Foo.number(DB查询)提供给其他进程?我没有使用数据库事务。
Rails 3.2.9
,Apache
,Phusion_Passenger 4
编辑
请注意,foo1
和foo2
在数据库中的不同的记录,我要的是能够看到过程1的过程2和foo2.number反之亦然,使我可以让其中一个重复。
谢谢@ethyl,请注意''foo1'和'foo2'是数据库中的不同记录,我想要的是能够'process1'看到'process2'的'foo2.number',反之亦然,这样我可以使其中的一个重复。 (编辑上面的问题) – Saim