update decorator to not create decorated functions per request#10
Conversation
While the existing implementation is simple it: creates a decorated function per request, calls it, and then will discard it. Since the functionality is straightforward and also encapsulated fairly well in Django, this PR modifies the decorator to copy the original Django decorator, and calls the same helper functions where possible. Because the functionality is no longer simply wrapping Django's internal implementation, but is still mostly the same, there have been tests added to compare the requests generated by Django vs requests generated by Django Request Framework/this library. Finally, in order to be less confusing to library writers the call signature of `etag_func` and `last_modified_func` has been updated to match Django Request Framework and will pass a DRF Request object instead of Django's native Request object:: # from the original signature def original_etag_func(wsgi_request, *args, **kwargs): pass # to the updated signature def updated_etag_func(drf_self, drf_request, *args, **kwargs): pass In order to ease the transition between the two signatures, there has been a flag "use_self" added to the decorators, and a warning will be emitted if use_self has not been set to True.
Codecov Report
@@ Coverage Diff @@
## master #10 +/- ##
===========================================
- Coverage 100.00% 92.85% -7.15%
===========================================
Files 2 2
Lines 21 42 +21
===========================================
+ Hits 21 39 +18
- Misses 0 3 +3
Continue to review full report at Codecov.
|
|
@jozo not sure if you have time to look over this PR? |
|
Thank you for your PR @terencehonles . I'm wondering what is the benefit of this PR. Is it performance? If so, how much it improves it? Does it outweigh simplicity of the current implementation? |
|
Well the bigger/biggest benefit is if you need to use the As far as performance I figured this was likely just overlooked, but I don't expect Django's conditions expected to be used this way. |
While the existing implementation is simple it: creates a decorated function per request, calls it, and then will discard it. Since the
functionality is straightforward and also encapsulated fairly well in Django, this PR modifies the decorator to copy the original Django decorator, and calls the same helper functions where possible.
Because the functionality is no longer simply wrapping Django's internal implementation, but is still mostly the same, there have been tests added to compare the requests generated by Django vs requests generated by Django Request Framework/this library.
Finally, in order to be less confusing to library writers the call signature of
etag_funcandlast_modified_funchas been updated to match Django Request Framework and will pass a DRF Request object insteadof Django's native Request object:
In order to ease the transition between the two signatures, there has been a flag "use_self" added to the decorators, and a warning will be emitted if use_self has not been set to True.