I prepared a patch that fixes the following bugs in beaker sessions:
1.
Problem: The first time the session is accessed, the _access_time is
updated and it is immediately saved back.
Solution: Defer saving of the session to the end of the request.
2.
Problem: If the session is accessed but not modified, it still gets
saved to the storage manager.
Solution: If the session was not modified, don't save it.
Note: The solution is the new default behavior. To override it and
revert to the old behavior of saving the session even if it was only
accessed, you can use the setting: beaker.session.auto = True
3.
Problem: Anytime someone calls session.save() the session is first
loaded and then saved.
Solution: Do not perform a redundant load before the saving the
session object.
4.
Problem: If session.save() is called multiple times during a request,
then the session will be saved multiple times.
Solution: Only save the session once at the end of the request, if
necessary.
So with this fix the following hypothetical action only loads and
saves the session once instead of three times :
class HelloController(BaseController):
def index(self):
x = session.get('x')
session['item1']='val1'
session.save()
session['item2']='val2'
session.save()
return render('/hello.html')
On Jan 7, 2:16 pm, Ben Bangert <[email protected]> wrote:
> On Jan 7, 2009, at 11:14 AM, Tycon wrote:
>
> > I agree that it's better to let users set the "dirty" flag if they
> > want.
>
> > It would also be great if you can change the Session.load() method to
> > NOT save the session immediately after loading it (not at the end of
> > the request), as is the case today. This auto-saving upon first access
> > is quite useless because subsequent changes to the session during the
> > same request need to be saved separately afterwards. The Session.load
> > () method can set the "dirty" flag if the "autosave" options is
> > "if_accessed".
>
> > Together these changes can help avoiding the multiple save() that is
> > happening today every time the session is used.
>
> Definitely. I'd be happy to review a patch to the code if you'd like
> to add these features, right now I'm heavily focused on Pylons 0.9.7
> release so it'll be a few weeks before I can get back to the Beaker
> code-base myself. Feel free to email me directly about any patches
> (with unit tests) to this and I can apply them.
>
> I'm sure your suggestion of not saving immediately upon load will also
> help session performance, which has been one of our goals for awhile
> too.
>
> Cheers,
> Ben
>
> smime.p7s
> 3KViewDownload
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---