mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 20:16:44 +00:00
Prefetch RuleSet objects for group (#5725)
* Prefetch RuleSet objects for group - Prevent multiple unnecessary db queries * Tweak * Default to previous behavior * Revert closer to original
This commit is contained in:
parent
ccaece3634
commit
1b7f943946
@ -420,16 +420,23 @@ def update_group_roles(group, debug=False):
|
|||||||
if permission_string not in permissions_to_add:
|
if permission_string not in permissions_to_add:
|
||||||
permissions_to_delete.add(permission_string)
|
permissions_to_delete.add(permission_string)
|
||||||
|
|
||||||
|
# Pre-fetch all the RuleSet objects
|
||||||
|
rulesets = {
|
||||||
|
r.name: r for r in RuleSet.objects.filter(group=group).prefetch_related('group')
|
||||||
|
}
|
||||||
|
|
||||||
# Get all the rulesets associated with this group
|
# Get all the rulesets associated with this group
|
||||||
for r in RuleSet.RULESET_CHOICES:
|
for r in RuleSet.RULESET_CHOICES:
|
||||||
|
|
||||||
rulename = r[0]
|
rulename = r[0]
|
||||||
|
|
||||||
try:
|
if rulename in rulesets:
|
||||||
ruleset = RuleSet.objects.get(group=group, name=rulename)
|
ruleset = rulesets[rulename]
|
||||||
except RuleSet.DoesNotExist:
|
else:
|
||||||
# Create the ruleset with default values (if it does not exist)
|
try:
|
||||||
ruleset = RuleSet.objects.create(group=group, name=rulename)
|
ruleset = RuleSet.objects.get(group=group, name=rulename)
|
||||||
|
except RuleSet.DoesNotExist:
|
||||||
|
ruleset = RuleSet.objects.create(group=group, name=rulename)
|
||||||
|
|
||||||
# Which database tables does this RuleSet touch?
|
# Which database tables does this RuleSet touch?
|
||||||
models = ruleset.get_models()
|
models = ruleset.get_models()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user