Skip to content

Commit

Permalink
refactor(access): prefetch team related fields
Browse files Browse the repository at this point in the history
ref: #471 #473
  • Loading branch information
jon-nfc committed Jan 16, 2025
1 parent ccb95c6 commit 033ac30
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions app/access/mixins/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,16 @@ def get_user_organizations(self, user: User) -> list([int]):

_user_permissions: list([ str ]) = []

for group in user.groups.all():
for group in user.groups.all().prefetch_related('team__permissions__content_type').prefetch_related('team__organization'):

team = group.team

team = teams.get(pk=group.id)

if team not in _user_teams:

_user_teams += [ team ]

for permission in team.permissions.all():
for permission in group.team.permissions.all():

permission_value = str( permission.content_type.app_label + '.' + permission.codename )

Expand Down
2 changes: 1 addition & 1 deletion app/access/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def get_queryset(self):

from settings.models.app_settings import AppSettings

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

Expand Down

0 comments on commit 033ac30

Please sign in to comment.