[RBAC] memoize user.singleton_permissions()
in Django (redis) cache
#224
Labels
user.singleton_permissions()
in Django (redis) cache
#224
As documented in
rbac.md
docs, enabling the global roles for users, and enabling global roles for teams, both incur 1 additional query per request. This can be knocked down significantly by simply using the local redis cache, avoiding round-tripping to a database serving an entire cluster. Ping @john-westcott-ivIn AWX we have a simple decorator that stores the return value in the cache.
https://github.com/ansible/awx/blob/8ff7260bc66f4de9aa177cb81ba83da3a2f53ec8/awx/main/utils/common.py#L171
Note that this uses
from django.core.cache import cache
which is the standard Django cache framework.https://docs.djangoproject.com/en/5.0/topics/cache/
The use case of getting singleton permissions is a perfect use case for this because:
Note that Django does not offer this
@memoize
decorator. That's fine, since it's in AWX it is ours to adopt. We should move it into DAB utils, and have AWX import from there. The method is written in a very widely compatible way.The text was updated successfully, but these errors were encountered: