Optimization request - give ``request.session`` lazy read

99 views
Skip to first unread message

Yo-Yo Ma

unread,
Sep 30, 2012, 10:24:20 PM9/30/12
to django-d...@googlegroups.com
With ``contrib.sessions`` installed and ``SessionMiddleware`` in use, I noticed that when Django session cookie is set the ``django_session`` table is queried on every request, regardless of whether any session data is used during the request cycle. Making the ``session`` attribute of request a lazy object would represent an optimization in the following 2 cases, both of which are the same, in effect:

1) User logs in to perform login-required tasks, then visits pages that don't require login
2) User logs in to perform login-required tasks, logs out, then visits pages that don't require login

Would this sort of change be backward-incompatible?

jdetaeye

unread,
Oct 2, 2012, 3:54:23 AM10/2/12
to Django developers

If the query is a problem for you that requires optimization, you're
probably better off using cookie-based sessions.

Aymeric Augustin

unread,
Oct 2, 2012, 5:39:00 AM10/2/12
to django-d...@googlegroups.com
2012/10/2 jdetaeye <johan.d...@gmail.com>

If the query is a problem for you that requires optimization, you're
probably better off using cookie-based sessions.

Either that, or the cache backend.

Sessions are the easiest thing to move out of the database when you have scaling problems.

--
Aymeric.
Reply all
Reply to author
Forward
0 new messages