provide faster alternative dmr.compiled.request_accepts instead of django.http HttpRequest.accepts#854
Conversation
Merging this PR will improve performance by 15.92%
Performance Changes
Comparing |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #854 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 339 339
Lines 13632 13654 +22
Branches 426 429 +3
=========================================
+ Hits 13632 13654 +22 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
sobolevn
left a comment
There was a problem hiding this comment.
Nice, great stuff! Please, add a changelog entry.
dmr/_compiled/negotiation.py
Outdated
| return accepted_type(header_value, (media_type,)) is not None | ||
|
|
||
|
|
||
| def request_accepts(request: _HasHeadersAsMapping, media_type: str) -> bool: |
There was a problem hiding this comment.
Maybe accepted_header? Since we are going to remove the request.
There was a problem hiding this comment.
not fully sure about the resulted name and the docstring though... naming things is hard...
|
love the fact that even pure python one is still manages to be faster than native django impl :) |
…django.http `HttpRequest.accepts`
|
Wow, great work! I obviously missed the |
dmr/_compiled/negotiation.py
Outdated
| # changed in the dict | ||
| self.params_str = ''.join(type_str.partition(';')[1:]) | ||
| self.params_str = ( | ||
| f';{type_str.partition(";")[2]}' if ';' in type_str else '' |
There was a problem hiding this comment.
you can use noqa here, since we are going for speed, not readability.
| f';{type_str.partition(";")[2]}' if ';' in type_str else '' | |
| f';{type_str.partition(";")[2]}' if ';' in type_str else '' # noqa: WPS237 |
| return None | ||
|
|
||
|
|
||
| def accepts(request: HttpRequest, content_type: str) -> bool: |
There was a problem hiding this comment.
This is a very different function. It checks that a selected renderer has a required content type.
Since you pass */* it always returns True now, when it should not, that's why tests fail :)
Let's add an argument strict: bool = True, when it is true pass '', when false, pass */*
also revert some things that i don't fully understand
| key=_by_priority, | ||
| reverse=True, | ||
| ) | ||
| if not accept_value or length_hint(provided_types) == 0: |
There was a problem hiding this comment.
mypyc calls python version of length_hint unfortunately, will revert
Refs: #851