Add User.get_local_site_stats for LocalSite membership info.
Review Request #12310 — Created May 31, 2022 and submitted
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 astate_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 thestate_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 |
---|---|
1791ec99749102d66f0c7c06127f258add061e07 |
- Change Summary:
-
User.get_local_site_stats()
now show-circuits the cache and database queries if the database lacks LocalSites. - Commits:
-
Summary ID 9db7348a0bafd9de468d2f6bf8d7fa7cabf02c32 b3d17626c25360901adca49e02792a849de82f3f