Opened 3 years ago

Closed 3 years ago

#33433 closed Cleanup/optimization (fixed)

Avoid calling resolve() when unnecessary in technical_404_response

Reported by: Hrushikesh Vaidya Owned by: Hrushikesh Vaidya
Component: Core (URLs) Version: 4.0
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

As discussed in the comments of this PR, we can avoid calling resolve(request.path) in the technical_404_response if request.resolver_match is already set.

This fix first checks if the resolver is None before calling resolve(), and avoids the call entirely if we have already resolved.

caller = ''
if resolver_match is None:
    try:
        resolver_match = resolve(request.path)
    except Http404:
        pass

if resolver_match is not None:
    caller = resolver_match._func_path

Change History (4)

comment:1 by Mariusz Felisiak, 3 years ago

Owner: changed from nobody to Hrushikesh Vaidya
Status: newassigned
Triage Stage: UnreviewedAccepted

comment:2 by Hrushikesh Vaidya, 3 years ago

comment:3 by Mariusz Felisiak, 3 years ago

Triage Stage: AcceptedReady for checkin

comment:4 by Mariusz Felisiak <felisiak.mariusz@…>, 3 years ago

Resolution: fixed
Status: assignedclosed

In 18a15bbc:

Fixed #33433 -- Avoided unnecessary resolve() calls in technical_404_response().

Thanks Keryn Knight for the initial patch.

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