mirror of https://github.com/zulip/zulip.git
Clean up rate_limit() for deployments that opt out.
If settings.RATE_LIMITING is False, short circuit rate limiting earlier in rate_limit(). This change particularly avoids inspect request.user and possibly spamming the error log for sites that don't care about rate limiting.
This commit is contained in:
parent
801bcdd956
commit
8e528569a7
|
@ -546,6 +546,12 @@ def rate_limit(domain='all'):
|
||||||
def wrapped_func(request, *args, **kwargs):
|
def wrapped_func(request, *args, **kwargs):
|
||||||
# type: (HttpRequest, *Any, **Any) -> HttpResponse
|
# type: (HttpRequest, *Any, **Any) -> HttpResponse
|
||||||
|
|
||||||
|
# It is really tempting to not even wrap our original function
|
||||||
|
# when settings.RATE_LIMITING is False, but it would make
|
||||||
|
# for awkward unit testing in some situations.
|
||||||
|
if not settings.RATE_LIMITING:
|
||||||
|
return func(request, *args, **kwargs)
|
||||||
|
|
||||||
if client_is_exempt_from_rate_limiting(request):
|
if client_is_exempt_from_rate_limiting(request):
|
||||||
return func(request, *args, **kwargs)
|
return func(request, *args, **kwargs)
|
||||||
|
|
||||||
|
@ -556,7 +562,6 @@ def rate_limit(domain='all'):
|
||||||
# doing the right thing here.
|
# doing the right thing here.
|
||||||
user = None
|
user = None
|
||||||
|
|
||||||
if not settings.RATE_LIMITING or not user:
|
|
||||||
if not user:
|
if not user:
|
||||||
logging.error("Requested rate-limiting on %s but user is not authenticated!" % \
|
logging.error("Requested rate-limiting on %s but user is not authenticated!" % \
|
||||||
func.__name__)
|
func.__name__)
|
||||||
|
|
Loading…
Reference in New Issue