Skip to content

Commit

Permalink
refactor(access): cache app settings during model fetch
Browse files Browse the repository at this point in the history
ref: #469 #471
  • Loading branch information
jon-nfc committed Jan 16, 2025
1 parent 7f16a06 commit 9d776e1
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions app/access/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 9d776e1

Please sign in to comment.