hello list, i''ve got the following code snippet in my model to generate extra helper functions. def transform_to_boolean Property.columns.select {|c| c.sql_type == "varchar(1)"}.each do |col| define_method "#{col.name.to_s}".to_sym do v = self.attributes[col.name.to_s] v = (v ? v.upcase : "F") if (v == "W" || v == "T") true else false end end end end this functionality takes over 1,2 sec for one instance of the model. It has to iterate over 260 columns. Do you have an idea how to speed up this piece of functionality? best regards, matthias -- 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.
On 7 Mai, 10:46, inriz <matthias.zirnst...-Mmb7MZpHnFY@public.gmane.org> wrote:> hello list, > > i''ve got the following code snippet in my model to generate extra > helper functions. > > def transform_to_boolean > Property.columns.select {|c| c.sql_type == "varchar(1)"}.each do > |col| > define_method "#{col.name.to_s}".to_sym do > v = self.attributes[col.name.to_s] > v = (v ? v.upcase : "F") > if (v == "W" || v == "T") > true > else > false > end > end > end > end > > this functionality takes over 1,2 sec for one instance of the model. > It has to iterate over 260 columns. > > Do you have an idea how to speed up this piece of functionality? > > best regards, > > matthias > > -- > 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@googlegroups.com. > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.this is the call of evil v = self.attributes[col.name.to_s] i change it to v = self.read_attribute(col.name.to_sym) its much faster. -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On May 7, 9:46 am, inriz <matthias.zirnst...-Mmb7MZpHnFY@public.gmane.org> wrote:> this functionality takes over 1,2 sec for one instance of the model. > It has to iterate over 260 columns. > > Do you have an idea how to speed up this piece of functionality? >why do you need to call this on each instance ? Fred -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.