rate_limit: Remove domain arg to the rate_limit decorator.

This option of specifying a different domain isn't used anywhere as of
now and we don't have a concrete way it could be used in the near
future. It's also getting in the way of how we want to do rate limiting
by IP, for which we'll want to apply a new domain 'api_by_ip'. That's
incompatible with how this decorator wants to determine the domain based
on the argument it receives when called to decorate a view function.

If in the future we want to have more granular control over API domains,
this can be refactored to be more general, but as of now it's just
imposing restrictions on how we can write the rate limiting code inside
it.
This commit is contained in:
Mateusz Mandera
2021-07-08 14:46:47 +02:00
committed by Tim Abbott
parent 3b4f8cc85b
commit 5e8e843613

View File

@@ -847,11 +847,8 @@ def rate_limit_user(request: HttpRequest, user: UserProfile, domain: str) -> Non
RateLimitedUser(user, domain=domain).rate_limit_request(request)
def rate_limit(domain: str = "api_by_user") -> Callable[[ViewFuncT], ViewFuncT]:
"""Rate-limits a view. Takes an optional 'domain' param if you wish to
rate limit different types of API calls independently.
Returns a decorator"""
def rate_limit() -> Callable[[ViewFuncT], ViewFuncT]:
"""Rate-limits a view. Returns a decorator"""
def wrapper(func: ViewFuncT) -> ViewFuncT:
@wraps(func)
@@ -878,7 +875,7 @@ def rate_limit(domain: str = "api_by_user") -> Callable[[ViewFuncT], ViewFuncT]:
return func(request, *args, **kwargs)
assert isinstance(user, UserProfile)
rate_limit_user(request, user, domain)
rate_limit_user(request, user, domain="api_by_user")
return func(request, *args, **kwargs)