Speed up user search indexing by fixing query cache usage for profiles.
Review Request #15013 — Created April 15, 2026 and submitted — Latest diff uploaded
User.get_profile()has checks in place to make use of any profile
fetched along with the user viaselect_related()or
prefetch_related().In the case where the cached profile result is a
None, we were falling
back on default behavior based on thecreate_if_missingflag. This is
fine if the flag isTrue(we want to create) but if the flag is
Falsea redundant fetch would occur, which would likely still return a
Noneresult.This code now respects a
Noneentry in the cache in this case, which
will raiseProfile.DoesNotExistas it would have before, but without
the redundant database query.This will significantly speed up search indexing for users, which was
performing 4 queries per user.
Unit tests pass.
Built new unit tests (for an upcoming change) that found this issue and
verified the fix.