Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tags and Taggings preload #48

Open
romaind opened this issue Feb 11, 2013 · 2 comments
Open

Tags and Taggings preload #48

romaind opened this issue Feb 11, 2013 · 2 comments

Comments

@romaind
Copy link

romaind commented Feb 11, 2013

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?

@fntz
Copy link
Contributor

fntz commented Feb 11, 2013

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.

@mauriciopasquier
Copy link

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

@dipil-saud
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants