Add ReviewRequest.clear_local_caches for ReviewRequest state clearing.

Review Request #14318 — Created Feb. 2, 2025 and updated

Information

Review Board
release-7.1.x

Reviewers

We have a few things that we cache on a ReviewRequest in order to
speed up repeated lookups (particulary for the review request page),
with more coming. These caches are on the object itself, so there's no
shared state between separate representations of the same review
request, but it helps to avoid a lot of repeated database queries.

The problem is, when a draft is published or discarded we don't clear
all this state. We do clear the file attachment state, but not the
review request blocks list, approval states, or loaded diffsets. This
isn't a major issue outside of unit tests, but could pose confusing
problems in the future, and will be getting worse with upcoming changes.

We now have a new function designed to clear local caches on the object:
ReviewRequest.clear_local_caches(). This doesn't need to be called
manually, but is called whenever a review request is published or a
draft is otherwise deleted.

It's worth noting that the deletion of a draft only resets caches for
the ReviewRequest object directly associated with it in memory, and
not any other instances in memory. This is fine for the purposes of
these caches.

Several missing unit tests for functions on ReviewRequest have been
added to test the basic caching functionality and the cache reset.

All unit tests pass.

Summary ID
Add ReviewRequest.clear_local_caches for ReviewRequest state clearing.
We have a few things that we cache on a `ReviewRequest` in order to speed up repeated lookups (particulary for the review request page), with more coming. These caches are on the object itself, so there's no shared state between separate representations of the same review request, but it helps to avoid a lot of repeated database queries. The problem is, when a draft is published or discarded we don't clear all this state. We do clear the file attachment state, but not the review request blocks list, approval states, or loaded diffsets. This isn't a major issue outside of unit tests, but could pose confusing problems in the future, and will be getting worse with upcoming changes. We now have a new function designed to clear local caches on the object: `ReviewRequest.clear_local_caches()`. This doesn't need to be called manually, but is called whenever a review request is published or a draft is otherwise deleted. It's worth noting that the deletion of a draft only resets caches for the `ReviewRequest` object directly associated with it in memory, and not any other instances in memory. This is fine for the purposes of these caches.
627878a06ab882b7c6ac725264f82fe37c1c121e
Checks run (2 succeeded)
flake8 passed.
JSHint passed.
david
  1. Ship It!
  2. 
      
maubin
  1. Ship It!
  2.