When I inspect the session hash, it shows me lots of entries that I have assigned a nil value to at some point. Is that taking up a lot of space? What is a good way to get rid of these useless entries? I am generally trying to reduce the size of my session hash. Is there a note with tips about this? Thanks, Arun -- 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 Feb 4, 7:46 am, arunmehta <arun.me...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> When I inspect the session hash, it shows me lots of entries that I > have assigned a nil value to at some point. Is that taking up a lot of > space? > > What is a good way to get rid of these useless entries? >You should probably track down where they are getting set. Fred> I am generally trying to reduce the size of my session hash. Is there > a note with tips about this? > > Thanks, > Arun-- 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.
Robert Pankowecki (rupert)
2011-Feb-04 20:09 UTC
Re: how to get rid of nil values in session?
How about deleting them in some after filter ? session.keys.each do |k| session.delete(k) if session[k].nil? end However you must be aware that sometimes in you application there might be a difference between nil value and unset key (usually it is a very rare case). Robert Pankowecki http://robert.pankowecki.pl -- 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 Feb 5, 1:09 am, "Robert Pankowecki (rupert)" <robert.pankowe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> How about deleting them in some after filter ? > > session.keys.each do |k| > session.delete(k) if session[k].nil? > endThanks, Robert, but... session is not a regular hash, and does not seem to have the delete function as above. Another suggestion, please? Warmly, Arun -- 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.
Robert Pankowecki (rupert)
2011-Feb-05 08:33 UTC
Re: how to get rid of nil values in session?
According to the documentation it inherits from Hash and has delete method. http://api.rubyonrails.org/classes/ActionDispatch/Session/AbstractStore/SessionHash.html#method-i-clear -- 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 Feb 5, 1:33 pm, "Robert Pankowecki (rupert)" <robert.pankowe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> According to the documentation it inherits from Hash and has delete > method. > > http://api.rubyonrails.org/classes/ActionDispatch/Session/AbstractSto...Thanks for all the trouble you are taking, Robert. I added the line: logger.info session.keys.inspect upon which it gave me an error: undefined method ''keys'' for #<CGI::Session:... and when I look at ri CGI::Session, it tells me, "data can be set and retrieved by indexing the Session instance using ''[]'', much the same as hashes (although other hash methods are not supported)." I am running rails 2.1.0, whereas the documentation you pointed me to, relates to 3.0.3 -- sorry I did not mention that sooner. Warmly, Arun -- 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.
Maybe there is no need to delete the keys on the session if those have nil as value. Probably rails doesn''t pass them into the cookie anyway. But I would do an experiment to make sure. -- Thanks, Ivan Povalyukhin On Feb 5, 2:40 am, arunmehta <arun.me...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Feb 5, 1:33 pm, "Robert Pankowecki (rupert)" > > <robert.pankowe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > According to the documentation it inherits from Hash and has delete > > method. > > >http://api.rubyonrails.org/classes/ActionDispatch/Session/AbstractSto... > > Thanks for all the trouble you are taking, Robert. I added the line: > > logger.info session.keys.inspect > > upon which it gave me an error: > > undefined method ''keys'' for #<CGI::Session:... > > and when I look at ri CGI::Session, it tells me, "data can be set and > retrieved by indexing the Session instance using ''[]'', much the same > as hashes (although other hash methods are not supported)." > > I am running rails 2.1.0, whereas the documentation you pointed me to, > relates to 3.0.3 -- sorry I did not mention that sooner. > > Warmly, Arun-- 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 Feb 5, 7:02 am, arunmehta <arun.me...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Feb 5, 1:09 am, "Robert Pankowecki (rupert)" > > <robert.pankowe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > How about deleting them in some after filter ? > > > session.keys.each do |k| > > session.delete(k) if session[k].nil? > > end > > Thanks, Robert, but... > session is not a regular hash, and does not seem to have the delete > function as above. Another suggestion, please?Why not try to avoid putting nil in the first place? Fred> > Warmly, > Arun-- 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.
Robert Pankowecki (rupert)
2011-Feb-06 08:27 UTC
Re: how to get rid of nil values in session?
On Feb 6, 12:47 am, ivanpoval <ivanpo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Maybe there is no need to delete the keys on the session if those have > nil as value. Probably rails doesn''t pass them into the cookie anyway. > But I would do an experiment to make sure.Session Hash storage is usually a database/files/memcached, not cookies. The reason for that is that you cannot trust cookies. Unless you put something into the cookie, Rails app will only store a sessions_id that is used by Rails framework to find session hash. In another words. Always use session to store important data. Use cookies to store unimportant things if you want them to last longer then the session. Robert Pankowecki -- 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 6 February 2011 08:27, Robert Pankowecki (rupert) <robert.pankowecki-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Feb 6, 12:47 am, ivanpoval <ivanpo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> Maybe there is no need to delete the keys on the session if those have >> nil as value. Probably rails doesn''t pass them into the cookie anyway. >> But I would do an experiment to make sure. > > Session Hash storage is usually a database/files/memcached, not > cookies.I thought that the default was to use cookies for session store. In which case storage will definitely usually be cookies as most users will just use the default. Colin> The reason for that is that you cannot trust cookies. Unless > you put something into the cookie, Rails app will only store a > sessions_id that is used by Rails framework to find session hash. In > another words. Always use session to store important data. Use cookies > to store unimportant things if you want them to last longer then the > session.-- 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 Feb 6, 12:47 am, ivanpoval <ivanpo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> Maybe there is no need to delete the keys on the session if those have > >> nil as value. Probably rails doesn''t pass them into the cookie anyway. > >> But I would do an experiment to make sure. > > > Session Hash storage is usually a database/files/memcached, not > > cookies. > > I thought that the default was to use cookies for session store. In > which case storage will definitely usually be cookies as most users > will just use the default.Colin, you are absolutely right. The default session store is CookieStore. There are also other options like DRbStore, MemCacheStore and ActiveRecordStore. I''m not sure about "Files". Files were used in Rails 1 but since Rails 2, the default storage of session data was moved to cookies. And that is very good, since dealing with files to store the session data is a complete headache. -- Thanks, Ivan Povalyukhin @ivanpovalyukhin -- 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.