From ff16260024954ce86f66412c9a0314b13198a0fc Mon Sep 17 00:00:00 2001 From: feng <1304903146@qq.com> Date: Mon, 19 Dec 2022 15:35:28 +0800 Subject: [PATCH] perf: remove OrganizationMember model --- .../orgs/migrations/0013_alter_organization_options.py | 3 --- apps/orgs/migrations/0014_organization_builtin.py | 3 +++ apps/users/models/user.py | 2 +- utils/generate_fake_data/resources/users.py | 10 ---------- 4 files changed, 4 insertions(+), 14 deletions(-) diff --git a/apps/orgs/migrations/0013_alter_organization_options.py b/apps/orgs/migrations/0013_alter_organization_options.py index 6dfd004da..e868a87a3 100644 --- a/apps/orgs/migrations/0013_alter_organization_options.py +++ b/apps/orgs/migrations/0013_alter_organization_options.py @@ -14,7 +14,4 @@ class Migration(migrations.Migration): name='organization', options={'permissions': (('view_rootorg', 'Can view root org'), ('view_alljoinedorg', 'Can view all joined org')), 'verbose_name': 'Organization'}, ), - migrations.DeleteModel( - name='OrganizationMember', - ), ] diff --git a/apps/orgs/migrations/0014_organization_builtin.py b/apps/orgs/migrations/0014_organization_builtin.py index 6541fe1a7..a9b407ffc 100644 --- a/apps/orgs/migrations/0014_organization_builtin.py +++ b/apps/orgs/migrations/0014_organization_builtin.py @@ -27,4 +27,7 @@ class Migration(migrations.Migration): field=models.BooleanField(default=False, verbose_name='Builtin'), ), migrations.RunPython(update_builtin_org), + migrations.DeleteModel( + name='OrganizationMember', + ), ] diff --git a/apps/users/models/user.py b/apps/users/models/user.py index 2534837b5..d6137add9 100644 --- a/apps/users/models/user.py +++ b/apps/users/models/user.py @@ -871,7 +871,7 @@ class User(AuthMixin, TokenMixin, RoleMixin, MFAMixin, AbstractUser): def delete(self, using=None, keep_parents=False): if self.pk == 1 or self.username == 'admin': return - return super(User, self).delete() + return super(User, self).delete(using=using, keep_parents=keep_parents) @classmethod def get_user_allowed_auth_backend_paths(cls, username): diff --git a/utils/generate_fake_data/resources/users.py b/utils/generate_fake_data/resources/users.py index 34a9d9703..c05e0793b 100644 --- a/utils/generate_fake_data/resources/users.py +++ b/utils/generate_fake_data/resources/users.py @@ -25,15 +25,6 @@ class UserGenerator(FakeDataGenerator): def pre_generate(self): self.group_ids = list(UserGroup.objects.all().values_list('id', flat=True)) - def set_org(self, users): - relations = [] - for u in users: - relations.append(OrganizationMember( - org_id=self.org.id, - user_id=u.id, - )) - OrganizationMember.objects.bulk_create(relations, ignore_conflicts=True) - def set_groups(self, users): relations = [] for i in users: @@ -55,5 +46,4 @@ class UserGenerator(FakeDataGenerator): ) users.append(u) users = User.objects.bulk_create(users, ignore_conflicts=True) - self.set_org(users) self.set_groups(users)