为应用程序运行rake searchkick:reindex CLASS=Product会导致Rake进程泄漏内存;大约15-20分钟后,就足以冻结一个内存为16 of的Debian系统。有3800条“产品”记录。
我设法用Rake任务中的以下代码解决了这个问题:
connection = ActiveRecord::Base.connection
res = connection.execute('select max(id) from products')
id = res.getvalue(0,0)
1.upto(id) do |i|
p = Product.find_by_id(i)
next unless p
p.reindex
end这也要快一点。
有人能提出调查这个记忆泄漏的方法吗?在考虑开一张票之前,最好更详细地这样做。
发布于 2022-04-28 15:32:04
这会导致生成索引时出现问题:Text fields are not optimised for operations that require per-document field data
可以通过在上面的代码中添加以下内容来解决这个问题:
Product.reindex(import: false)
# Rest of code goes here...https://stackoverflow.com/questions/71334743
复制相似问题