rocket_tag icon indicating copy to clipboard operation
rocket_tag copied to clipboard

Tags and Taggings preload

Open romaind opened this issue 12 years ago • 2 comments

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?

romaind avatar Feb 11 '13 19:02 romaind

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.

fntz avatar Feb 11 '13 20:02 fntz

But setting @setup_for_rocket_tag would also disable the before_save callback defined there too, that seems important :P

mauriciopasquier avatar Mar 10 '13 11:03 mauriciopasquier

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?

dipil-saud avatar Apr 01 '13 11:04 dipil-saud