|
39 | 39 |
|
40 | 40 | def migrate_groups_for_tenant(tenant: Tenant, replicator: RelationReplicator):
|
41 | 41 | """Generate user relationships and system role assignments for groups in a tenant."""
|
42 |
| - groups = tenant.group_set.values("pk") |
| 42 | + groups = tenant.group_set.only("pk").values("pk") |
43 | 43 | for group in groups:
|
44 | 44 | # The migrator deals with concurrency control.
|
45 | 45 | # We need an atomic block because the select_for_update is used in the dual write handler,
|
@@ -72,16 +72,16 @@ def migrate_groups_for_tenant(tenant: Tenant, replicator: RelationReplicator):
|
72 | 72 |
|
73 | 73 | def migrate_roles_for_tenant(tenant, exclude_apps, replicator):
|
74 | 74 | """Migrate all roles for a given tenant."""
|
75 |
| - roles = tenant.role_set.all() |
| 75 | + roles = tenant.role_set.only("pk") |
76 | 76 | if exclude_apps:
|
77 | 77 | roles = roles.exclude(access__permission__application__in=exclude_apps)
|
78 |
| - |
79 |
| - for role in roles: |
| 78 | + role_pks = roles.values_list("pk", flat=True) |
| 79 | + for role in role_pks: |
80 | 80 | # The migrator deals with concurrency control and roles needs to be locked.
|
81 | 81 | with transaction.atomic():
|
82 |
| - logger.info(f"Migrating role: {role.name} with UUID {role.uuid}.") |
83 | 82 | # Requery and lock role
|
84 |
| - role = Role.objects.select_for_update().get(pk=role.pk) |
| 83 | + role = Role.objects.select_for_update().get(pk=role) |
| 84 | + logger.info(f"Migrating role: {role.name} with UUID {role.uuid}.") |
85 | 85 | dual_write_handler = RelationApiDualWriteHandler(
|
86 | 86 | role, ReplicationEventType.MIGRATE_CUSTOM_ROLE, replicator
|
87 | 87 | )
|
|
0 commit comments