File tree Expand file tree Collapse file tree 2 files changed +22
-4
lines changed
Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Original file line number Diff line number Diff line change 115115 'DEFAULT_FILTER_BACKENDS' : ['django_filters.rest_framework.DjangoFilterBackend' ],
116116 'PAGE_SIZE' : 100 ,
117117 'DEFAULT_THROTTLE_CLASSES' : [
118- 'rest_framework.throttling.AnonRateThrottle' ,
119- 'rest_framework.throttling.UserRateThrottle' ,
118+ 'quickbooks_desktop_api.throttles.PerUserPathThrottle' ,
120119 ],
121120 'DEFAULT_THROTTLE_RATES' : {
122- 'anon' : '10/second' ,
123- 'user' : '10/second'
121+ 'per_user_path' : '30/second'
124122 }
125123}
126124
Original file line number Diff line number Diff line change 1+ from rest_framework .throttling import SimpleRateThrottle
2+
3+
4+ class PerUserPathThrottle (SimpleRateThrottle ):
5+ scope = 'per_user_path'
6+
7+ def allow_request (self , request , view ):
8+ if not request .user or not request .user .is_authenticated :
9+ return True
10+
11+ return super ().allow_request (request , view )
12+
13+ def get_cache_key (self , request , view ):
14+ if not request .user or not request .user .is_authenticated :
15+ return None
16+
17+ ident = request .user .pk
18+ normalized_path = request .path .replace ('/' , '_' ).strip ('_' )
19+
20+ return f"throttle_{ self .scope } _{ normalized_path } _{ ident } "
You can’t perform that action at this time.
0 commit comments