hey there, i have a simple model called key_words.rb the purpose of this is to hold system config data. it also holds the parameters that our system uses to judge the condition of the stuff we monitor. anyway, one of the methods is this def self.get_in_wet_list(status) wet_list = find(:first, :conditions => "name = ''wet_list'' ") wet_list.message.split('','').include?(status) end my question is.... we use this to process a lot of information, sometimes a few thousand records will go thru this and i think it could be a performance killer. i wanted to make this a session variable so that it would not have to go to the database and redraw it a few thousand times on a page refresh. so i thought def self.get_in_wet_list(status) wet_list = session[:wet_list] if wet_list.nil? wet_list = find(:first, :conditions => "name = ''wet_list'' ") end wet_list.message.split('','').include?(status) end the only thing is that a model does not seem to be able to access session variables. at any rate, does someone have an idea about how to make this work better ? thanks --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 1/16/07, nephish <nephish-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> at any rate, does someone have an idea about how to make this work > better ?What you''re looking for is caching. Check out BackgrounDRb or something similiar. If your wet_list is fairly static and not too massive you could cache it in a class variable, too: class WetList < ActiveRecord::Base @@wet_list_cache = nil def self.get_in_wet_list(status) @@wet_list_cache ||= find_by_name(''wet_list'') @@wet_list_cache.message.split('','').include? status end def after_save @@wet_list_cache = nil end end -- Chris Wanstrath http://errtheblog.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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
thanks a whole lot ! yes, the variable is fairly static, changes maybe once a week or month. is small too, and example would be wet_list = ''w,W,ww,rw'' and thats it. thanks so much for this help ! sk On 1/17/07, Chris Wanstrath <chris-G5sj8e7vJc8@public.gmane.org> wrote:> > > On 1/16/07, nephish <nephish-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > at any rate, does someone have an idea about how to make this work > > better ? > > What you''re looking for is caching. Check out BackgrounDRb or > something similiar. > > If your wet_list is fairly static and not too massive you could cache > it in a class variable, too: > > class WetList < ActiveRecord::Base > @@wet_list_cache = nil > > def self.get_in_wet_list(status) > @@wet_list_cache ||= find_by_name(''wet_list'') > @@wet_list_cache.message.split('','').include? status > end > > def after_save > @@wet_list_cache = nil > end > end > > -- > Chris Wanstrath > http://errtheblog.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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
ok, one more thing, i have a wet_list, but also have a dry_list , fwd_list, etc... i suppose i could lump them all into one class and each list could be another method. so does rails keep up with this model for the whole session ? thanks ! shawn --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
forget it, i went ahead and tried it and it worked like a charm, pages are loading much much faster. thanks for taking your time on this for me, Chris. You really made a difference --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---