• 
      

    Improve usage and optimize lookups of get_profile() and get_site_profile().

    Review Request #10388 — Created Jan. 22, 2019 and submitted

    Information

    Review Board
    release-3.0.x

    Reviewers

    User.get_profile() and User.get_site_profile() have diverged over
    time, in terms of implementation and usage. get_profile() used to only
    fetch profiles, requiring them to be created through some other means,
    but these days it's guaranteed to return a result. It also gained the
    ability to fetch via cache. get_site_profile() still worked like the
    old get_profile() did, however, and required a lot more work from
    callers. Much of the code in the codebase using these methods were
    outdated and doing too much, creating extra SQL queries and ignoring any
    previously-cached profiles.

    This change works to modernize profile lookups and usage. Both methods
    now accept the same arguments.

    • cached_only controls whether to only consider profile results in the
      existing cache.

    • create_if_missing controls whether to create an entry in the
      database if it doesn't already exist (which now defaults to True for
      both, creating consistent behavior).

    • return_is_new alters the return value to return a tuple containing
      the profile and an is_new boolean, letting callers be a bit smarter
      about whether operations on a profile need to be performed.

    Call sites have been updated to take advantage of the new arguments and
    behavior. Many callers that previously did their own get_or_create()
    now benefit from the cache. Old calls checking for exceptions no longer
    need to, or now pass create_if_missing=False. Default values computed
    in the absence of a profile have been removed.

    We also had many places where we were saving the entirety of profiles
    unnecessarily. In some cases, we'd be performing a double-save of the
    same data. We now no longer do this, and when we do want to save, we're
    explicit about what fields we're updating. This helps avoid conflicts
    and reduces database writes.

    All unit tests pass.

    Went through the product and tested most affected areas. There is a
    chance of some subtle fallout/behavioral changes, which will require
    further testing on reviews.reviewboard.org.

    Summary ID
    Improve usage and optimize lookups of get_profile() and get_site_profile().
    `User.get_profile()` and `User.get_site_profile()` have diverged over time, in terms of implementation and usage. `get_profile()` used to only fetch profiles, requiring them to be created through some other means, but these days it's guaranteed to return a result. It also gained the ability to fetch via cache. `get_site_profile()` still worked like the old `get_profile()` did, however, and required a lot more work from callers. Much of the code in the codebase using these methods were outdated and doing too much, creating extra SQL queries and ignoring any previously-cached profiles. This change works to modernize profile lookups and usage. Both methods now accept the same arguments. * `cached_only` controls whether to only consider profile results in the existing cache. * `create_if_missing` controls whether to create an entry in the database if it doesn't already exist (which now defaults to `True` for both, creating consistent behavior). * `return_is_new` alters the return value to return a tuple containing the profile and an `is_new` boolean, letting callers be a bit smarter about whether operations on a profile need to be performed. Call sites have been updated to take advantage of the new arguments and behavior. Many callers that previously did their own `get_or_create()` now benefit from the cache. Old calls checking for exceptions no longer need to, or now pass `create_if_missing=False`. Default values computed in the absence of a profile have been removed. We also had many places where we were saving the entirety of profiles unnecessarily. In some cases, we'd be performing a double-save of the same data. We now no longer do this, and when we do want to save, we're explicit about what fields we're updating. This helps avoid conflicts and reduces database writes.
    041ca03f3cbdcdffde928900d920f0df830d5280
    Description From Last Updated

    F841 local variable 'profile' is assigned to but never used

    reviewbotreviewbot

    F821 undefined name 'uset'

    reviewbotreviewbot
    Checks run (1 failed, 1 succeeded)
    flake8 failed.
    JSHint passed.

    flake8

    chipx86
    Review request changed
    Change Summary:
    • Removed an unused variable.
    • Simplified some logic in datagrid columns.
    Commits:
    Summary ID
    Improve usage and optimize lookups of get_profile() and get_site_profile().
    `User.get_profile()` and `User.get_site_profile()` have diverged over time, in terms of implementation and usage. `get_profile()` used to only fetch profiles, requiring them to be created through some other means, but these days it's guaranteed to return a result. It also gained the ability to fetch via cache. `get_site_profile()` still worked like the old `get_profile()` did, however, and required a lot more work from callers. Much of the code in the codebase using these methods were outdated and doing too much, creating extra SQL queries and ignoring any previously-cached profiles. This change works to modernize profile lookups and usage. Both methods now accept the same arguments. * `cached_only` controls whether to only consider profile results in the existing cache. * `create_if_missing` controls whether to create an entry in the database if it doesn't already exist (which now defaults to `True` for both, creating consistent behavior). * `return_is_new` alters the return value to return a tuple containing the profile and an `is_new` boolean, letting callers be a bit smarter about whether operations on a profile need to be performed. Call sites have been updated to take advantage of the new arguments and behavior. Many callers that previously did their own `get_or_create()` now benefit from the cache. Old calls checking for exceptions no longer need to, or now pass `create_if_missing=False`. Default values computed in the absence of a profile have been removed. We also had many places where we were saving the entirety of profiles unnecessarily. In some cases, we'd be performing a double-save of the same data. We now no longer do this, and when we do want to save, we're explicit about what fields we're updating. This helps avoid conflicts and reduces database writes.
    77edcebfbb9462e6b1bcf173186159019a600ee3
    Improve usage and optimize lookups of get_profile() and get_site_profile().
    `User.get_profile()` and `User.get_site_profile()` have diverged over time, in terms of implementation and usage. `get_profile()` used to only fetch profiles, requiring them to be created through some other means, but these days it's guaranteed to return a result. It also gained the ability to fetch via cache. `get_site_profile()` still worked like the old `get_profile()` did, however, and required a lot more work from callers. Much of the code in the codebase using these methods were outdated and doing too much, creating extra SQL queries and ignoring any previously-cached profiles. This change works to modernize profile lookups and usage. Both methods now accept the same arguments. * `cached_only` controls whether to only consider profile results in the existing cache. * `create_if_missing` controls whether to create an entry in the database if it doesn't already exist (which now defaults to `True` for both, creating consistent behavior). * `return_is_new` alters the return value to return a tuple containing the profile and an `is_new` boolean, letting callers be a bit smarter about whether operations on a profile need to be performed. Call sites have been updated to take advantage of the new arguments and behavior. Many callers that previously did their own `get_or_create()` now benefit from the cache. Old calls checking for exceptions no longer need to, or now pass `create_if_missing=False`. Default values computed in the absence of a profile have been removed. We also had many places where we were saving the entirety of profiles unnecessarily. In some cases, we'd be performing a double-save of the same data. We now no longer do this, and when we do want to save, we're explicit about what fields we're updating. This helps avoid conflicts and reduces database writes.
    8d05184a3b4cb65c3e442beff84569d8af557c33

    Checks run (1 failed, 1 succeeded)

    flake8 failed.
    JSHint passed.

    flake8

    chipx86
    david
    1. Ship It!
    2. 
        
    chipx86
    Review request changed
    Status:
    Completed
    Change Summary:
    Pushed to release-3.0.x (eda20e4)