Hi, I am having one performance issue. I want to retrieve different kind of data from a single table with different conditions. here is example @licences = Licence.scoped_by_user_id(10) usedpermlicence = @licences.scoped_by_status_and_licence_type(1, 0) usedtemplicence = @licences.scoped_by_status_and_licence_type(1, 1) remainlicence = @licences.scoped_by_status_and_licence_type(0, 0) remaintemplicence = @licences.scoped_by_status_and_licence_type(0, 1) Please let me know is there any way to store all the licences into one object and can retrieve data from this object without any db query. Thanks in Advance Hitesh Rawal -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> > @licences = Licence.scoped_by_user_id(10) > usedpermlicence = @licences.scoped_by_status_and_licence_type(1, 0) > usedtemplicence = @licences.scoped_by_status_and_licence_type(1, 1) > remainlicence = @licences.scoped_by_status_and_licence_type(0, 0) > remaintemplicence = @licences.scoped_by_status_and_licence_type(0, > 1) > > Please let me know is there any way to store all the licences into one > object and can retrieve data from this object without any db query. >Sure: usedpermlicence = @licences.select {|o| o.status == 1 && o.licence_type =0} usedtemplicence = @licences.select {|o| o.status == 1 && o.licence_type =1} etc... You can treat @licences as an array and just select the items you want. One DB query (which you''re already doing) and a quick bit of filtering. http://ruby-doc.org/core/classes/Array.html#M002191 Cheers, Andy -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks Andy, For ur quick reply and valuable suggestion. I followed your suggestion and It improved performance and decrease the no. of db queries. Thanks Andy Jeffries wrote:>> > Sure: > > usedpermlicence = @licences.select {|o| o.status == 1 && o.licence_type > => 0} > usedtemplicence = @licences.select {|o| o.status == 1 && o.licence_type > => 1} > > etc... > > You can treat @licences as an array and just select the items you want. > One > DB query (which you''re already doing) and a quick bit of filtering. > > http://ruby-doc.org/core/classes/Array.html#M002191 > > Cheers, > > > Andy-- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.