-
Notifications
You must be signed in to change notification settings - Fork 468
feat: Add rate limiting to identity search endpoint #6438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
eb6c827
db1cc77
14dc93f
aa244d5
a11a21e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
| from rest_framework import status, viewsets | ||
| from rest_framework.permissions import IsAuthenticated | ||
| from rest_framework.response import Response | ||
| from rest_framework.throttling import ScopedRateThrottle | ||
|
|
||
| from app.pagination import CustomPagination | ||
| from core.constants import FLAGSMITH_UPDATED_AT_HEADER, SDK_ENVIRONMENT_KEY_HEADER | ||
|
|
@@ -41,6 +42,15 @@ | |
| class IdentityViewSet(viewsets.ModelViewSet): # type: ignore[type-arg] | ||
| serializer_class = IdentitySerializer | ||
| pagination_class = CustomPagination | ||
| throttle_scope = "identity_search" | ||
|
|
||
1-23-smy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def get_throttles(self): # type: ignore[no-untyped-def] | ||
| """ | ||
| Apply identity_search throttle only to list (search) requests. | ||
| """ | ||
| if getattr(self, "action", None) == "list": | ||
| return [ScopedRateThrottle()] | ||
| return [] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even though the impact is minimal, i would suggest to return the global default throttle |
||
|
|
||
| def get_queryset(self): # type: ignore[no-untyped-def] | ||
| if getattr(self, "swagger_fake_view", False): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,10 +4,10 @@ import useDebounce from './useDebounce' | |
| export default function useDebouncedSearch(initialValue = '') { | ||
| const [searchInput, setSearchInput] = useState(initialValue) | ||
| const [search, setSearch] = useState(initialValue) | ||
| const [debounceTime, setDebounceTime] = useState(500) | ||
| const [debounceTime, setDebounceTime] = useState(750) | ||
|
|
||
| useEffect(() => { | ||
| setDebounceTime(searchInput.length < 1 ? 0 : 500) | ||
| setDebounceTime(searchInput.length < 1 ? 0 : 750) | ||
|
Comment on lines
+7
to
+10
|
||
| }, [searchInput]) | ||
|
|
||
| const debouncedSearch = useDebounce((value: string) => { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.