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

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

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.

Commits

Files