我有一个User.rb
包含以下行的模型:
acts_as_taggable_on :industries, :uxes
[“uxes”术语包含属于用户的 UX 偏好,例如他们是否关闭了某个帮助框。]
我注意到的是,每个涉及 a 的请求的顶部都会加载以下查询@user
:
User Load (1.4ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 354 LIMIT 1
ActsAsTaggableOn::Tag Load (0.4ms) SELECT `tags`.* FROM `tags` INNER JOIN `taggings` ON `tags`.id = `taggings`.tag_id WHERE ((`taggings`.taggable_id = 354) AND (`taggings`.taggable_type = 'User')) AND (taggings.context = 'uxes' AND taggings.tagger_id IS NULL)
AREL (0.3ms) UPDATE `users` SET `last_request_at` = '2012-09-17 09:44:24', `perishable_token` = 'un5eK7SHDNzTegt7GPUk', `updated_at` = '2012-09-17 09:44:24' WHERE `users`.`id` = 354
ActsAsTaggableOn::Tag Load (0.3ms) SELECT `tags`.* FROM `tags` INNER JOIN `taggings` ON `tags`.id = `taggings`.tag_id WHERE ((`taggings`.taggable_id = 354) AND (`taggings`.taggable_type = 'User')) AND (taggings.context = 'uxes' AND taggings.tagger_id IS NULL)
ActsAsTaggableOn::Tagging Load (0.4ms) SELECT `taggings`.* FROM `taggings` WHERE `taggings`.`tagger_type` IS NULL AND `taggings`.`tagger_id` IS NULL AND `taggings`.`context` = 'uxes' AND `taggings`.`tag_id` IN (NULL) AND (`taggings`.taggable_id = 354 AND `taggings`.taggable_type = 'User')
这些查询增加了加载用户的每个页面加载的时间(即所有页面加载的 90% 以上)。为什么要acts_as_taggable
强制这些查询发生,除非必要,否则我如何阻止它加载它们?