summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Robenolt <matt@ydekproductions.com>2015-10-27 12:05:37 -0700
committerMatt Robenolt <matt@ydekproductions.com>2015-10-27 12:08:00 -0700
commit4e2ca63ebd9ec1d684d5e0661e11bd6f1dc275e8 (patch)
tree374561042aa87b7934b8c45e60879f28eaec9b91
parent4d34f712f2216a75e783f9f76a9dd3c08fb4839e (diff)
downloadraven-cached-property.tar.gz
Use cached_property for getting client in the Django middlewarecached-property
Since we need to lazy import the client inside the @property, we incur the overhead of importing every time. This overhead is minimal, ~0.7usec on my machine, but this is done on every request, 3 times per request which adds up to ~2.1usec. As a @cached_property, this gets transformed directly into the __dict__ of the instance, and brings the time down to ~0.04usec per lookup, which is over an order of magnitude faster after the initial call.
-rw-r--r--raven/contrib/django/middleware/wsgi.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/raven/contrib/django/middleware/wsgi.py b/raven/contrib/django/middleware/wsgi.py
index 643fb32..2fcaf32 100644
--- a/raven/contrib/django/middleware/wsgi.py
+++ b/raven/contrib/django/middleware/wsgi.py
@@ -7,13 +7,14 @@ raven.contrib.django.middleware.wsgi
"""
from __future__ import absolute_import
+from django.utils.functional import cached_property
from raven.middleware import Sentry
class Sentry(Sentry):
"""
Identical to the default WSGI middleware except that
- the client comes dynamically via ``get_client
+ the client comes dynamically via ``get_client``
>>> from raven.contrib.django.middleware.wsgi import Sentry
>>> application = Sentry(application)
@@ -21,7 +22,7 @@ class Sentry(Sentry):
def __init__(self, application):
self.application = application
- @property
+ @cached_property
def client(self):
from raven.contrib.django.models import client
return client