Clean up the code for a lot of our centralized query logic.

Review Request #12339 — Created June 3, 2022 and submitted

Information

Review Board
release-5.0.x

Reviewers

This is a basic cleanup change that improves the readability of several
of the larger query-building functions in our model managers. This
mainly centers around:

  1. Consistent naming (q vs. queryset instead of query being used
    for either or qs sometimes being used).

  2. |= and &= instead of q = q | or q = q &.

  3. Doing as much with Q() objects as possible before calling methods
    like filter(...).

  4. Starting with a Q() object before any conditional logic, instead of
    starting fresh inside of conditionals, to avoid potential issues with
    logic being overridden unintentionally.

  5. General formatting improvements to help readability of some logic
    when combining Q() objects.

  6. Using our modern chaining-like formatting for multi-line queryset
    conditionals (chaining filter() and order_by() across lines, for
    instance).

This helps ensure more consistent code going forward, and lays a
foundation for some query optimization work that is coming.

All unit tests pass.

Summary ID
Clean up the code for a lot of our centralized query logic.
This is a basic cleanup change that improves the readability of several of the larger query-building functions in our model managers. This mainly centers around: 1. Consistent naming (`q` vs. `queryset` instead of `query` being used for either or `qs` sometimes being used). 2. `|=` and `&=` instead of `q = q |` or `q = q &`. 3. Doing as much with `Q()` objects as possible before calling methods like `filter(...)`. 4. Starting with a `Q()` object before any conditional logic, instead of starting fresh inside of conditionals, to avoid potential issues with logic being overridden unintentionally. 5. General formatting improvements to help readability of some logic when combining `Q()` objects. 6. Using our modern chaining-like formatting for multi-line queryset conditionals (chaining `filter()` and `order_by()` across lines, for instance). This helps ensure more consistent code going forward, and lays a foundation for some query optimization work that is coming.
dded5eb906a36ae94de036e04bc95fbc7251ba22
Description From Last Updated

F821 undefined name 'query'

reviewbotreviewbot

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

reviewbotreviewbot

can get rid of this since we create q on line 122

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

flake8

chipx86
maubin
  1. 
      
  2. reviewboard/reviews/managers.py (Diff revision 2)
     
     
    Show all issues

    can get rid of this since we create q on line 122

  3. 
      
chipx86
david
  1. Ship It!
  2. 
      
chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to release-5.0.x (6fbfc20)