Note that there are some explanatory texts on larger screens.

plurals
  1. POacts_as_taggable runs queries on every request
    primarykey
    data
    text
    <p>I have a <code>User.rb</code> model that includes the line:</p> <pre><code>acts_as_taggable_on :industries, :uxes </code></pre> <p>[The 'uxes' term contains UX preferences belonging to the user, such as whether they dismissed a certain help box.]</p> <p>What I've noticed is the following queries are loading at the top of every request involving a <code>@user</code>:</p> <pre><code>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') </code></pre> <p>These queries are adding time to every pageload on which a user is loaded (i.e. 90%+ of all pageloads). Why is <code>acts_as_taggable</code> forcing these queries to occur, and how can I stop it from loading them unless necessary?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload