rocket_tag
rocket_tag copied to clipboard
Tags and Taggings preload
Hi,
Thanks for the gem, it's awesome ! Sorry in advance if I'm opening an issue on a topic that already has been addressed.
I'm questionning about the goal of these lines in https://github.com/bradphelan/rocket_tag/blob/master/lib/rocket_tag/taggable.rb:
default_scope do
preload{taggings}.preload{tags}
end
I can imagine why tags are being preloaded but in my case it causes performance issues as it loads the taggings for every user all the time, even though I don't need them in some listings of my app.
I've tried removing these lines and it improves performances on my side and it still loads tags when they are needed.
Does someone have thoughts about that?
It's simpy. Set @setup_for_rocket_tag
in true
before attr_taggable
calling. For example
class Post < AR::B
@setup_for_rocket_tag = true
attr_taggable :tags
end
Now preload disabled.
But setting @setup_for_rocket_tag
would also disable the before_save
callback defined there too, that seems important :P
As setting @setup_for_rocket_tag disabled the before_save callbacks, it wasn't automatically saving the tags when the parent is saved. So, hacked it by clearing the set default scopes. Just need to define other default scopes below this block.
class Post < AR::B
attr_taggable :tags
class_eval do
default_scopes.clear
end
end
Is there another better way?