On Sun, Sep 13, 2009 at 4:19 AM, pydon <[email protected]> wrote: > > Hopefully reading this correctly. > > So I cannot store a whole object in a session but instead should just > store a reference to it?
You can detach an ORM object from the database so that you can put it in a session or otherwise use it offline: meta.Session.expunge(user) However, it's generally better to store just the username. > Does this not require querying the database all the time for > information on this object? (recreate it when required) > > For instance every time I want the users name I would use the user id > in the session to query SA for the user and then check his/her name Only once per request. This is arguably a good idea anyway because the user's status/permissions may have changed between requests, either by the user at another computer (=another session) or by admin action. And a single query by primary key is very little overhead. The overhead comes with dozens of queries per request, especially if they have complex WHERE clauses or joins. But if your database can't handle one query per request for the user info, you need a bigger database server anyway, and right now. (Er, but I do store a user object in my session. But it's not a database user object.) If you're dealing with extremely frequent requests, you could compromise between the two by storing the current time in the session. Then at the next request, if the time difference is more than five minutes, you can re-query the database. But again, you should probably look for efficiencies elsewhere first. -- Mike Orr <[email protected]> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en -~----------~----~----~----~------~----~------~--~---
