Opened 3 weeks ago

Closed 3 weeks 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, 3 weeks ago

Triage Stage: UnreviewedAccepted

comment:2 by Adam Johnson, 3 weeks ago

Has patch: set

comment:3 by Mariusz Felisiak, 3 weeks ago

Triage Stage: AcceptedReady for checkin

comment:4 by GitHub <noreply@…>, 3 weeks ago

Resolution: fixed
Status: assignedclosed

In 41bc48a:

Fixed #36603 -- Optimized check order in LoginRequiredMiddleware.

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