Speed up user search indexing by fixing query cache usage for profiles.
Review Request #15013 — Created April 15, 2026 and updated
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,
returning theNonedirectly without the extra fetch.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.
| Summary | ID |
|---|---|
| a811778bca289d5549c5ab3e0db679d6212b4ef7 |