[英]Rails find_each is not working
Currently, I'm triggering a SuckerPunch Job via clockwork in my Rails app. 目前,我正在通过Rails应用中的发条来触发SuckerPunch作业。
User.find_each do |user|
puts "Found user: #{user.name}!"
end
# Doesn't work, too.
User.all.each do |user|
puts "Found user: #{user.name}!"
end
However, the execution stucks when searching for the users. 但是,搜索用户时执行卡住了。 When printing the
Enumerator
( User.find_each.inspect
) to the console it shows the users. 将
Enumerator
( User.find_each.inspect
)打印到控制台时,它将显示用户。 Why won't the block run? 为什么块不运行? May there be a Rails context missing?
可能会缺少Rails上下文吗?
It's been driving me crazy for hours. 几个小时使我发疯。 I'm deploying to Heroku, btw.
我正在部署到Heroku,顺便说一句。
EDIT: I figured out, there's an error: Primary key not included in the custom select clause
. 编辑:我发现,有一个错误:
Primary key not included in the custom select clause
。
Thanks in advance! 提前致谢!
I suspect you're hitting some sort of limit due to the number of Users in the db. 我怀疑您由于数据库中的用户数而达到某种限制。 Have you tried using find_in_batch instead?
您是否尝试过使用find_in_batch?
http://apidock.com/rails/ActiveRecord/Batches/find_each (uses find_in_batch with a default batch_size of 1000) http://apidock.com/rails/ActiveRecord/Batches/find_in_batches (note the last post) http://apidock.com/rails/ActiveRecord/Batches/find_each (使用find_in_batch,默认batch_size为1000) http://apidock.com/rails/ActiveRecord/Batches/find_in_batches (请注意最后一篇)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.