From 0b45d6f23620eb50963ef179d0aa9c2692703583 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 25 Sep 2023 13:35:13 +1000 Subject: [PATCH] Use prefetch to improve query efficiency (#5613) (#5614) - Significantly improves performance of users.models.update_group_roles() function - Ref: https://github.com/inventree/InvenTree/pull/5612 (cherry picked from commit 200bc5bd3d56ca2c1cd1a7cedab63e4cce0f5b5f) Co-authored-by: Oliver --- InvenTree/users/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InvenTree/users/models.py b/InvenTree/users/models.py index d6f5c05214..30c594915a 100644 --- a/InvenTree/users/models.py +++ b/InvenTree/users/models.py @@ -373,7 +373,7 @@ def update_group_roles(group, debug=False): # Iterate through each permission already assigned to this group, # and create a simplified permission key string - for p in group.permissions.all(): + for p in group.permissions.all().prefetch_related('content_type'): (permission, app, model) = p.natural_key() permission_string = '{app}.{perm}'.format(