目前我正在开发一个大型Web应用程序并使其工作更快我决定重构所有N 1个查询(减少对数据库的请求数量,
http://rails-bestpractices.com/posts/29-fix-n-1-queries).所以我安装了gem“bullet”,它现在不适用于Rails 3.1.1(你可以使用
https://github.com/flyerhzm/bullet的fork).在每个页面上使用declarative_authorization gem时,我会收到相同的警报:
N+1 Query detected
Role => [:permissions]
Add to your finder: :include => [:permissions]
N+1 Query detected
Permission => [:permission_rules]
Add to your finder: :include => [:permission_rules]
CACHE (0.0ms) SELECT "roles".* FROM "roles"
CACHE (0.0ms) SELECT "permissions".* FROM "permissions" WHERE "permissions"."role_id" = 1
CACHE (0.0ms) SELECT "permissions".* FROM "permissions" WHERE "permissions"."role_id" = 2
CACHE (0.0ms) SELECT "permissions".* FROM "permissions" WHERE "permissions"."role_id" = 3
CACHE (0.0ms) SELECT "permissions".* FROM "permissions" WHERE "permissions"."role_id" = 4
CACHE (0.0ms) SELECT "permissions".* FROM "permissions" WHERE "permissions"."role_id" = 6
CACHE (0.0ms) SELECT "permissions".* FROM "permissions" WHERE "permissions"."role_id" = 7
CACHE (0.0ms) SELECT "permissions".* FROM "permissions" WHERE "permissions"."role_id" = 8
CACHE (0.0ms) SELECT "permission_rules".* FROM "permission_rules" INNER JOIN "permission_rules_permissions" ON "permission_rules"."id" = "permission_rules_permissions"."permission_rule_id" WHERE "permission_rules_permissions"."permission_id" = 30
CACHE (0.0ms) SELECT "permission_rules".* FROM "permission_rules" INNER JOIN "permission_rules_permissions" ON "permission_rules"."id" = "permission_rules_permissions"."permission_rule_id" WHERE "permission_rules_permissions"."permission_id" = 31
...
你可以帮我解决这个问题吗?
最佳答案 我会删除宝石,但添加:包括在两个模型中的每一个.