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 3cee11a commit 4e8bb88
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 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,19 @@ 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

app_settings = AppSettings.objects.prefetch_related('global_organization').get(
owner_organization = None
)

self._app_settings = app_settings

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 All @@ -196,7 +202,7 @@ def get_queryset(self):

if user.is_authenticated:

for team_user in TeamUsers.objects.filter(user=user):
for team_user in TeamUsers.objects.filter(user=user).prefetch_related('team__organization'):


if team_user.team.organization.name not in user_organizations:
Expand Down

0 comments on commit 4e8bb88

Please sign in to comment.