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

globalize2 makes too many extra queries #33

Open
pupeno opened this issue Jun 10, 2010 · 11 comments
Open

globalize2 makes too many extra queries #33

pupeno opened this issue Jun 10, 2010 · 11 comments

Comments

@pupeno
Copy link

pupeno commented Jun 10, 2010

I'm trying to lower the amount of queries my app is making and half of the queries are due to globalize2 and I couldn't found a way to minimize that.

http://stackoverflow.com/questions/3006938/fetch-main-model-and-translations-in-one-query-with-globalize2

@hukl
Copy link
Collaborator

hukl commented Jun 10, 2010

I was minimizing queries by running Post.all(:include => :translations) That worked a couple of months ago before svenfuchs refactoring - it should still work. Does that help you ?

@pupeno
Copy link
Author

pupeno commented Jun 10, 2010

It didn't work for me:

Page.all(:include => :translation)
  Page Load (0.4ms)   SELECT SQL_NO_CACHE * FROM `pages` 
ActiveRecord::ConfigurationError: Association named 'translation' was not found; perhaps you misspelled it?
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:115:in `preload_one_association'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activesupport-2.3.5/lib/active_support/ordered_hash.rb:97:in `each'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activesupport-2.3.5/lib/active_support/ordered_hash.rb:97:in `each'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:114:in `preload_one_association'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:91:in `preload_associations'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:90:in `preload_associations'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:90:in `each'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:90:in `preload_associations'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/base.rb:1550:in `find_every'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/base.rb:615:in `find'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/base.rb:635:in `all'
        from (irb):2

@hukl
Copy link
Collaborator

hukl commented Jun 10, 2010

uhm try the plural: :translations

@pupeno
Copy link
Author

pupeno commented Jun 10, 2010

I actually tried both, not sure why I pasted the singular one.

Page.all(:include => :translations)
  Page Load (0.3ms)   SELECT SQL_NO_CACHE * FROM `pages` 
ActiveRecord::ConfigurationError: Association named 'translations' was not found; perhaps you misspelled it?
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:115:in `preload_one_association'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activesupport-2.3.5/lib/active_support/ordered_hash.rb:97:in `each'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activesupport-2.3.5/lib/active_support/ordered_hash.rb:97:in `each'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:114:in `preload_one_association'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:91:in `preload_associations'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:90:in `preload_associations'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:90:in `each'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:90:in `preload_associations'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/base.rb:1550:in `find_every'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/base.rb:615:in `find'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/base.rb:635:in `all'
        from (irb):3

@hukl
Copy link
Collaborator

hukl commented Jun 10, 2010

okay sorry so its page_translations i guess - look it up in your schema ;)

@pupeno
Copy link
Author

pupeno commented Jun 10, 2010

hukl, are you meaning just a plain old Rails :include? I've tried that, but it didn't work, even though the table exist, the model and the association seem not to, there's no PageTranslation model:

Page.all(:include => :page_translations)
  Page Load (13.8ms)   SELECT SQL_NO_CACHE * FROM `pages` 
ActiveRecord::ConfigurationError: Association named 'page_translations' was not found; perhaps you misspelled it?
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:115:in `preload_one_association'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activesupport-2.3.5/lib/active_support/ordered_hash.rb:97:in `each'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activesupport-2.3.5/lib/active_support/ordered_hash.rb:97:in `each'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:114:in `preload_one_association'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:91:in `preload_associations'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:90:in `preload_associations'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:90:in `each'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:90:in `preload_associations'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/base.rb:1550:in `find_every'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/base.rb:615:in `find'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/base.rb:635:in `all'
        from (irb):4

@hukl
Copy link
Collaborator

hukl commented Jun 10, 2010

http://github.com/hukl/cccms/blob/master/app/models/page.rb

Not sure though if its using the latest globalize version

@pupeno
Copy link
Author

pupeno commented Jun 10, 2010

I'm sorry, I'm not sure what I'm looking at in there. Does that work with your code snippet? Your page looks like my page (regarding translations).

@hukl
Copy link
Collaborator

hukl commented Jun 10, 2010

come on - read the source luke - its really not that hard …

http://gist.github.com/432818

@pupeno
Copy link
Author

pupeno commented Jun 10, 2010

That might have worked in an old version of globalize2, but it doesn't work anymore.

ruby-1.8.7-p174 > Page.all(:include => [:page_translations])
  Page Load (22.3ms)   SELECT SQL_NO_CACHE * FROM `pages` 
ActiveRecord::ConfigurationError: Association named 'page_translations' was not found; perhaps you misspelled it?
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:115:in `preload_one_association'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activesupport-2.3.5/lib/active_support/ordered_hash.rb:97:in `each'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activesupport-2.3.5/lib/active_support/ordered_hash.rb:97:in `each'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:114:in `preload_one_association'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:91:in `preload_associations'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:90:in `preload_associations'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:90:in `each'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:90:in `preload_associations'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/base.rb:1550:in `find_every'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/base.rb:615:in `find'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/base.rb:635:in `all'
        from (irb):5
ruby-1.8.7-p174 > Page.all(:include => [:translations])
  Page Load (2.5ms)   SELECT SQL_NO_CACHE * FROM `pages` 
ActiveRecord::ConfigurationError: Association named 'translations' was not found; perhaps you misspelled it?
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:115:in `preload_one_association'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activesupport-2.3.5/lib/active_support/ordered_hash.rb:97:in `each'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activesupport-2.3.5/lib/active_support/ordered_hash.rb:97:in `each'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:114:in `preload_one_association'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:91:in `preload_associations'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:90:in `preload_associations'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:90:in `each'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/association_preload.rb:90:in `preload_associations'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/base.rb:1550:in `find_every'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/base.rb:615:in `find'
        from /Users/pupeno/.rvm/gems/ruby-1.8.7-p174@lemonfrog/gems/activerecord-2.3.5/lib/active_record/base.rb:635:in `all'
        from (irb):6

Maybe the old version set up an association, but without it, include won't ever work (adding the square brackets doesn't really change anything here).

@hukl
Copy link
Collaborator

hukl commented Jun 10, 2010

Sorry but for my example I created a fresh rails app and installed globalize2 from github

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

2 participants