Closed silva96 closed 2 years ago
Found the culprit,
User class is using devise
devise :database_authenticatable, :registerable, :confirmable,
:recoverable, :rememberable, :validatable, :trackable
UPDATE:
This will only happen when inspecting the result of User.last
call, as in the irb console.
calling with ;nil
disables the result inspection
irb(main):001:0> User.last;nil
User Load (0.8ms) SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT $1 [["LIMIT", 1]]
=> nil
When including devise authenticable, the inspect
method is overriden by this:
def inspect
inspection = serializable_hash.collect do |k,v|
"#{k}: #{respond_to?(:attribute_for_inspect) ? attribute_for_inspect(k) : v.inspect}"
end
"#<#{self.class} #{inspection.join(", ")}>"
end
which iterates over all and every attribute of the object, hence, calling the tag attributes and firing the queries.
Thanks a lot for that, wasnt easy to find I bet.
UPDATE: This is not a bug of the gem. this is caused only in the Console, with User model that includes devise authenticable module. See https://github.com/mbleigh/acts-as-taggable-on/issues/1075#issuecomment-1016706312
Tag queries are performed even though I'm not calling / using the tags, for example:
I don't use the tags everywhere I initialize a user, but it still queries the tags.
I would expect the queries be fired whenever I use something related the tags, like:
Adding a cache (
cached_tag_list
) reduces one queryWhat is weird is that I also have a
Post
model that has the same cache and tag column nameand it does not make a query