0
我遇到了一个相当奇怪的问题。我有以下的测试在我的路线之一:Sinatra应用程序(可能)调用数据库两次
error 404 unless Agreement.find_by(agreement_id: params[:agreement_id])
这是一个active record
模型,我只是使用提供find_by
方法。当我检查日志,这是输出:
D, [2014-03-25T09:40:06.207120 #5956] DEBUG -- : Agreement Load (0.1ms) SELECT "agreements".* FROM "agreements" WHERE "agreements"."agreement_id" = '<id>' LIMIT 1
127.0.0.1 - - [25/Mar/2014:09:40:06 +0100] "HEAD /agreements/<id> HTTP/1.1" 204 0.0142
D, [2014-03-25T09:40:06.216059 #5956] DEBUG -- : Agreement Load (0.2ms) SELECT "agreements".* FROM "agreements" WHERE "agreements"."agreement_id" = '<id>' LIMIT 1
所以,在我看来,两两件事正在发生的事情:要么数据库称为两次(坏的),或者它只是被记录两次(然而,这似乎并不是这种情况,因为查询显然不是以相同的速度运行(0.1ms与0.2ms))。
任何帮助将不胜感激。