Received: from mail.netlandish.com (mail.netlandish.com [174.136.98.166]) by code.netlandish.com (Postfix) with ESMTP id 73BAA81243 for <~petersanchez/public-inbox@lists.code.netlandish.com>; Tue, 22 Dec 2020 09:49:36 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=209.85.167.48; helo=mail-lf1-f48.google.com; envelope-from=mortas.11@gmail.com; receiver= Authentication-Results: mail.netlandish.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=Xgcd2/jg Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) by mail.netlandish.com (Postfix) with ESMTP id 5FAE7152FB1 for <~petersanchez/public-inbox@lists.code.netlandish.com>; Tue, 22 Dec 2020 09:49:33 +0000 (UTC) Received: by mail-lf1-f48.google.com with SMTP id h205so30525807lfd.5 for <~petersanchez/public-inbox@lists.code.netlandish.com>; Tue, 22 Dec 2020 01:49:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to:cc; bh=wi18BhqO7mSoWF/YQUB9ec16LojxWH6D2BPbaufN50U=; b=Xgcd2/jglMJnJeFiw1NTi1CdZ5pDbtg/z8khElKnYe8DZIT9fj7ebbd4nyWpcvOEbc 6cBksVzJPEPkgrlSM0X5BEj9zlGjMkE0EjKkonSrAkEHaeJztZwZv+mkcF7o2AuKjy+L STvKJUV2FClM9LvZ8xw7X7e9icmDZfCLusY1aeYOvSCvEr81hTEmxXxouk+4ZE9KfuSf Jw0/uTCd8pBoeUvWk0eRdMk+/Myk9SZkoXnNmP2JOw4m8qmd+ut7H8kwoIGS1y2bfX8a OU+VzYoItKpYfzEUXflMO4Qpg/MuPgxGGWFPLEJ6AnsNKqyzQuFLYDbaJ5M53/UC+U9P GSYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=wi18BhqO7mSoWF/YQUB9ec16LojxWH6D2BPbaufN50U=; b=Sqq9VfDd3utc5xZ6T1zAxOG2Z3vc/Q5dEsUXSHJNFSHDdvJsyaGYAozDIDAlC8WIHC 1u53OiTxztsVGZv9bb7F8vztrvmOSHy7XIB1RdzE04KeFkhz4aGocdCVnSwzh5eM2Dyk UBBXiiQd7mHnT+NNfkk8chlvB5RSnbtDfuPmOUVVcJixKDNwNuKgPlpWDtVc1zHqnXJm cYPrNDo0unklxy4cWyd8XC4OFOIm5XHTt1lYpKNqIegrnDiEch8C9kOGPbbNOXcw22fx rLZrvuG8+HGs8xtS+/ELObWutdZaWcWUJK1/EyRIvLlBqfEH8Q+843GunHBtjO3J1XfD jBow== X-Gm-Message-State: AOAM5310ci2A9id29eMbz61Tn2WgaAdwVZIOE0yf6MwXUoa9Un3B3KqY 1l0de+7iUOoAdZOOpqd3LOySbX0fagStgHMcqzurGo9Vkrc= X-Google-Smtp-Source: ABdhPJzXBOxvLucK4j6kn8ZlV23Pwx1JpKLGQUFTfM9zRBW60FkQtpBp0ErFMS4AiUpZG0PKkoITboY5XLPFSXFkPHs= X-Received: by 2002:a2e:780d:: with SMTP id t13mr9059048ljc.144.1608630572650; Tue, 22 Dec 2020 01:49:32 -0800 (PST) MIME-Version: 1.0 From: =?UTF-8?B?0JjQu9GM0Y8=?= Date: Tue, 22 Dec 2020 12:49:22 +0300 Message-ID: Subject: Re: [PATCH django-impersonate] optimization | preserve request.user laziness To: ~petersanchez/public-inbox@lists.code.netlandish.com Cc: Peter Sanchez Content-Type: text/plain; charset="UTF-8" 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: ....