~petersanchez/public-inbox

1

[PATCH django-impersonate] optimization | preserve request.user laziness

Илья
Details
Message ID
<CAJF=k3=Liko6RimSozkyM3eVDbo2XBMVTHoZs47HKVpAJ925hA@mail.gmail.com>
DKIM signature
missing
Download raw message
(I've used "reply in thread" link but it created separate topic, sorry)

In our case that means 100k+ requests every day =)

What do you think about this workaround? I've tested it locally.

class ImpersonateMiddleware(MiddlewareMixin):
    def process_request(self, request):
        _usr = request.user  # save as local var to prevent infinite recursion
        def _get_usr():
            _usr.is_impersonate = False
            return _usr

        request.user = SimpleLazyObject(_get_usr)
        request.impersonator = None

        if '_impersonate' in request.session and request.user.is_authenticated:
            ....
Details
Message ID
<20201223062642.cd6a4wbiy7cvb547@thinkpad>
In-Reply-To
<CAJF=k3=Liko6RimSozkyM3eVDbo2XBMVTHoZs47HKVpAJ925hA@mail.gmail.com> (view parent)
DKIM signature
missing
Download raw message
On 12/22, Илья wrote:
>class ImpersonateMiddleware(MiddlewareMixin):
>    def process_request(self, request):
>        _usr = request.user  # save as local var to prevent infinite recursion
>        def _get_usr():
>            _usr.is_impersonate = False
>            return _usr
>
>        request.user = SimpleLazyObject(_get_usr)
>        request.impersonator = None
>
>        if '_impersonate' in request.session and request.user.is_authenticated:
>            ....

This has been applied in changeset eed039f473c6

Thanks!
Reply to thread Export thread (mbox)