我正在尝试使用 bullet gem 标记 N+1 并在代码中添加计数器缓存的位置.但是手动执行所有检查 N+1 查询的操作似乎非常痛苦,所以我尝试使用 Bullet 和 Rspec,使用他们推荐的设置步骤:
# config/environments/test.rb
config.after_initialize do
Bullet.enable = true
Bullet.bullet_logger = true
Bullet.raise = true # raise an error if n+1 query occurs
end
# spec/spec_helper.rb
if Bullet.enable?
config.before(:each) do
Bullet.start_request
end
config.after(:each) do
Bullet.perform_out_of_channel_notifications if Bullet.notification?
Bullet.end_request
end
end
但是当我运行规范时,似乎在规范本身而不是应用程序中标记了 N+1 个查询。你知道是否有可能实现我想要的吗?
最佳答案
这实际上是 gem 中的一个错误,请在此处关注问题,评论并投票以获得更快的解决方案: https://github.com/flyerhzm/bullet/issues/407#issuecomment-437672707
关于ruby-on-rails - 在 Rspec 中用项目符号标记 N+1 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39334107/