From 9d776e14a41a974a5a1805d36026f6e095466242 Mon Sep 17 00:00:00 2001 From: Jon Date: Fri, 17 Jan 2025 02:17:04 +0930 Subject: [PATCH] refactor(access): cache app settings during model fetch ref: #469 #471 --- app/access/models.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/access/models.py b/app/access/models.py index 604ee0493..180352c80 100644 --- a/app/access/models.py +++ b/app/access/models.py @@ -143,6 +143,8 @@ class TenancyManager(models.Manager): This manager specifically caters for the multi-tenancy features of Centurion ERP. """ + _app_settings: any = None + def get_queryset(self): """ Fetch the data @@ -179,15 +181,17 @@ def get_queryset(self): if request: - from settings.models.app_settings import AppSettings + if not self._app_settings: - app_settings = AppSettings.objects.prefetch_related('global_organization').get( - owner_organization = None - ) + from settings.models.app_settings import AppSettings + + self._app_settings = AppSettings.objects.prefetch_related('global_organization').get( + owner_organization = None + ) - if app_settings.global_organization: + if self._app_settings.global_organization: - user_organizations += [ app_settings.global_organization.id ] + user_organizations += [ self._app_settings.global_organization.id ] # user = request.user._wrapped if hasattr(request.user,'_wrapped') else request.user