~petersanchez/public-inbox

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

Илья
Details
Message ID
<CAJF=k3nC7h-QXNCvJ2r_xfs3xMCbVg1n34jH2UJhVnW+tKJB-g@mail.gmail.com>
DKIM signature
missing
Download raw message
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:
            ....
Reply to thread Export thread (mbox)