Ticket #5513: sessions_speedup_6364.2.diff

File sessions_speedup_6364.2.diff, 1.6 KB (added by msaelices, 8 years ago)

This is good patch for minor improvements. The other patch is other question.

  • django/contrib/sessions/middleware.py

     
    44import datetime
    55import time
    66
     7engine = __import__(settings.SESSION_ENGINE, {}, {}, [''])
     8
    79TEST_COOKIE_NAME = 'testcookie'
    810TEST_COOKIE_VALUE = 'worked'
    911
    1012class SessionMiddleware(object):
    1113
    1214    def process_request(self, request):
    13       engine = __import__(settings.SESSION_ENGINE, {}, {}, [''])
     15      global engine
    1416      request.session = engine.SessionStore(request.COOKIES.get(settings.SESSION_COOKIE_NAME, None))
    1517
    1618    def process_response(self, request, response):
  • django/contrib/sessions/backends/base.py

     
    104104    def _get_session(self):
    105105        # Lazily loads session from storage.
    106106        self.accessed = True
    107         try:
     107        if hasattr(self, '_session_cache'):
    108108            return self._session_cache
    109         except AttributeError:
    110             if self.session_key is None:
    111                 self._session_cache = {}
    112             else:
    113                 self._session_cache = self.load()
     109        if self._session_key is None:
     110            self._session_cache = {}
     111        else:
     112            self._session_cache = self.load()
    114113        return self._session_cache
    115114
    116115    _session = property(_get_session)
Back to Top