Add User.get_local_site_stats for LocalSite membership info.

Review Request #12310 — Created May 31, 2022 and submitted — Latest diff uploaded

Information

Review Board
release-5.0.x

Reviewers

This introduces User.get_local_site_stats(), which provides a list of
IDs of LocalSites that the user is a member of, and LocalSites that the
user is an admin of, along with a state_uuid that can be used as part
of derived cache keys.

This enables quick lookup of LocalSite membership. The results are
cached, making it quick to call, saving up two database queries,
depending on the usage. The cache key makes use of the state_uuid from
LocalSite.objects.get_stats(), meaning that the cache will
automatically be invalidated any time the list of LocalSites change.

User.is_admin_for_user() makes use of this, benefiting from the cache.
The old version of this function did have a cached copy, but it didn't
correctly invalidate.

Unit tests pass.

Diff Revision 2

This is not the most recent revision of the diff. The latest diff is revision 3. See what's changed.

orig
1
2
3

Commits

First Last Summary ID Author
Add User.get_local_site_stats for LocalSite membership info.
This introduces `User.get_local_site_stats()`, which provides a list of IDs of LocalSites that the user is a member of, and LocalSites that the user is an admin of, along with a `state_uuid` that can be used as part of derived cache keys. This enables quick lookup of LocalSite membership. The results are cached, making it quick to call, saving up two database queries, depending on the usage. The cache key makes use of the `state_uuid` from `LocalSite.objects.get_stats()`, meaning that the cache will automatically be invalidated any time the list of LocalSites change. `User.is_admin_for_user()` makes use of this, benefiting from the cache. The old version of this function did have a cached copy, but it didn't correctly invalidate.
b3d17626c25360901adca49e02792a849de82f3f Christian Hammond
reviewboard/accounts/models.py
reviewboard/accounts/tests/test_user.py
Loading...