Add User.get_local_site_stats for LocalSite membership info.

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

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.

Summary ID
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.
1791ec99749102d66f0c7c06127f258add061e07
chipx86
chipx86
david
  1. Ship It!
  2. 
      
chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to release-5.0.x (7bbe7ff)