• 
      

    Speed up user search indexing by fixing query cache usage for profiles.

    Review Request #15013 — Created April 15, 2026 and updated

    Information

    Review Board
    release-7.1.x

    Reviewers

    User.get_profile() has checks in place to make use of any profile
    fetched along with the user via select_related() or
    prefetch_related().

    In the case where the cached profile result is a None, we were falling
    back on default behavior based on the create_if_missing flag. This is
    fine if the flag is True (we want to create) but if the flag is
    False a redundant fetch would occur, which would likely still return a
    None result.

    This code now respects a None entry in the cache in this case,
    returning the None directly 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
    Speed up user search indexing by fixing query cache usage for profiles.
    `User.get_profile()` has checks in place to make use of any profile fetched along with the user via `select_related()` or `prefetch_related()`. In the case where the cached profile result is a `None`, we were falling back on default behavior based on the `create_if_missing` flag. This is fine if the flag is `True` (we want to create) but if the flag is `False` a redundant fetch would occur, which would likely still return a `None` result. This code now respects a `None` entry in the cache in this case, returning the `None` directly without the extra fetch. This will significantly speed up search indexing for users, which was performing 4 queries per user.
    a811778bca289d5549c5ab3e0db679d6212b4ef7
    Checks run (2 succeeded)
    flake8 passed.
    JSHint passed.