Compare IDs instead of model instances when possible.

Review Request #10380 — Created Jan. 13, 2019 and submitted

Information

Review Board
release-3.0.x

Reviewers

We had several regularly-invoked model instance comparisons in the
product that could result in unwanted database queries. These were
usually found in accessibility checks, comparing if a requesting user
matches the user owning an object.

To reduce overhead, we now compare the IDs, which is faster even if the
instances were already loaded. This cuts down on a number of queries in
common usage.

Test coverage for these checks have been improved, with many
accessibility checks that were previously covered implicitly through
other test suites now having explicit test coverage.

There's also a fix for a bad permission name, which impacted the tests.
The can_edit_status permission for StatusUpdate needed to be
change_statusupdate.

Unit tests pass.

Summary ID
Compare IDs instead of model instances when possible.
We had several regularly-invoked model instance comparisons in the product that could result in unwanted database queries. These were usually found in accessibility checks, comparing if a requesting user matches the user owning an object. To reduce overhead, we now compare the IDs, which is faster even if the instances were already loaded. This cuts down on a number of queries in common usage. Test coverage for these checks have been improved, with many accessibility checks that were previously covered implicitly through other test suites now having explicit test coverage. There's also a fix for a bad permission name, which impacted the tests. The `can_edit_status` permission for `StatusUpdate` needed to be `change_statusupdate`.
228c527eb4dda2c60bd0359fccf0ada7ef3f3beb
Description From Last Updated

F821 undefined name 'AnonymousUser'

reviewbotreviewbot

F821 undefined name 'AnonymousUser'

reviewbotreviewbot

E128 continuation line under-indented for visual indent

reviewbotreviewbot

F401 'reviewboard.reviews.models.StatusUpdate' imported but unused

reviewbotreviewbot
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 (cd33f6d)