Assuming you have Person that has_many :messages, what will it happen if it has 10000 messages? Will rails attempt to initialize @person.messages with 10000 rows from database? If that is the case, is combining finder_sql and counter_sql the common practice to avoid this? Bogdan _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Bogdan, I think you want is something called lazy-loading (where an object's children are ONLY loaded when needed). I don't know if this is the default behaviour for ActiveRecord (I think so...), but hopefully someone else can clear that up for you. Jacob On 9/10/05, Bogdan Ionescu <bogdan.ionescu@gmail.com> wrote:> Assuming you have Person that has_many :messages, what will it happen if it > has 10000 messages? > Will rails attempt to initialize @person.messages with 10000 rows from > database? If that is the case, is combining finder_sql and counter_sql the > common practice to avoid this? > > Bogdan > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Lazy loading *is* the default method for Rails. However if a person does have 10000 messages why is it bad if your result returns 10000 messages? :) Julian. On 11/09/2005, at 4:34 AM, Jacob Quinn Shenker wrote:> Bogdan, > I think you want is something called lazy-loading (where an object''s > children are ONLY loaded when needed). I don''t know if this is the > default behaviour for ActiveRecord (I think so...), but hopefully > someone else can clear that up for you. > > Jacob > > On 9/10/05, Bogdan Ionescu <bogdan.ionescu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> Assuming you have Person that has_many :messages, what will it >> happen if it >> has 10000 messages? >> Will rails attempt to initialize @person.messages with 10000 rows >> from >> database? If that is the case, is combining finder_sql and >> counter_sql the >> common practice to avoid this? >> >> Bogdan >> >> >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> >> >> >> > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
i know *lazyily* loading 10,000 records when you need 1 is bad on the database, memory, and processor, and for no reason. personally i would use @person.messages.find and limit the number of returns. im not sure :include lets you do options. On 9/10/05, Julian Leviston <julian-AfxEtdRqmE/tt0EhB6fy4g@public.gmane.org> wrote:> Lazy loading *is* the default method for Rails. > > However if a person does have 10000 messages why is it bad if your > result returns 10000 messages? :) > > Julian. > > On 11/09/2005, at 4:34 AM, Jacob Quinn Shenker wrote: > > > Bogdan, > > I think you want is something called lazy-loading (where an object''s > > children are ONLY loaded when needed). I don''t know if this is the > > default behaviour for ActiveRecord (I think so...), but hopefully > > someone else can clear that up for you. > > > > Jacob > > > > On 9/10/05, Bogdan Ionescu <bogdan.ionescu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > >> Assuming you have Person that has_many :messages, what will it > >> happen if it > >> has 10000 messages? > >> Will rails attempt to initialize @person.messages with 10000 rows > >> from > >> database? If that is the case, is combining finder_sql and > >> counter_sql the > >> common practice to avoid this? > >> > >> Bogdan > >> > >> > >> _______________________________________________ > >> Rails mailing list > >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > >> http://lists.rubyonrails.org/mailman/listinfo/rails > >> > >> > >> > >> > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Zachery Hostens <zacheryph-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Zachery, On 15.9.2005, at 1.42, Zachery Hostens wrote:> i know *lazyily* loading 10,000 records when you need 1 is bad on the > database, memory, and processor, and for no reason.The whole idea of lazy loading is that you do *not* load the associated objects you don''t need.> > personally i would use @person.messages.find and limit the number of > returns.This is what is called lazy loading and it is the default method in ActiveRecord :-)> im not sure :include lets you do options.This, on the other hand, is called eager loading. It doesn''t let you specify options for the associated objects. //jarkko> > On 9/10/05, Julian Leviston <julian-AfxEtdRqmE/tt0EhB6fy4g@public.gmane.org> wrote: > >> Lazy loading *is* the default method for Rails. >> >> However if a person does have 10000 messages why is it bad if your >> result returns 10000 messages? :) >> >> Julian. >> >> On 11/09/2005, at 4:34 AM, Jacob Quinn Shenker wrote: >> >> >>> Bogdan, >>> I think you want is something called lazy-loading (where an object''s >>> children are ONLY loaded when needed). I don''t know if this is the >>> default behaviour for ActiveRecord (I think so...), but hopefully >>> someone else can clear that up for you. >>> >>> Jacob >>> >>> On 9/10/05, Bogdan Ionescu <bogdan.ionescu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> >>> >>>> Assuming you have Person that has_many :messages, what will it >>>> happen if it >>>> has 10000 messages? >>>> Will rails attempt to initialize @person.messages with 10000 rows >>>> from >>>> database? If that is the case, is combining finder_sql and >>>> counter_sql the >>>> common practice to avoid this? >>>> >>>> Bogdan >>>> >>>> >>>> _______________________________________________ >>>> Rails mailing list >>>> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>>> http://lists.rubyonrails.org/mailman/listinfo/rails >>>> >>>> >>>> >>>> >>>> >>> _______________________________________________ >>> Rails mailing list >>> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>> http://lists.rubyonrails.org/mailman/listinfo/rails >>> >>> >> >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> >> > > > -- > Zachery Hostens <zacheryph-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails