Opened 2 days ago

Closed 40 hours ago

#36603 closed Cleanup/optimization (fixed)

Make LoginRequiredMiddleware avoid fetching request.user for public views

Reported by: Adam Johnson Owned by: Adam Johnson
Component: contrib.auth Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

LoginRequiredMiddleware checks request.user.is_authenticated before view_func.login_required. This causes unnecessary database queries for public views, fetching the current session and user, even though the check doesn't need that information. Rearranging the condition checks to first see if the view is public would avoid that extra work.

Change History (4)

comment:1 by Simon Charette, 2 days ago

Triage Stage: Unreviewed → Accepted

comment:2 by Adam Johnson, 2 days ago

Has patch: set

comment:3 by Mariusz Felisiak, 40 hours ago

Triage Stage: Accepted → Ready for checkin

comment:4 by GitHub <noreply@â€Ļ>, 40 hours ago

Resolution: → fixed
Status: assigned → closed

In 41bc48a:

Fixed #36603 -- Optimized check order in LoginRequiredMiddleware.

Note: See TracTickets for help on using tickets.
Back to Top