Skip to content

Commit

Permalink
fix(executer.rdb): optimize batch creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Oo-RR-oO committed Aug 31, 2020
1 parent 07a6d4a commit 117399d
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions executer/RDB/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ def create_dept(self, dept_info):
# 1) 去重
perm_ids = Perm.valid_objects.values_list('pk', flat=True)
exist_perm_ids = DeptPerm.valid_objects.filter(owner=serializer.instance).values_list('perm_id', flat=True)
for item in exist_perm_ids:
perm_ids.remove(item)
perm_ids = set(perm_ids).difference(exist_perm_ids)
# 2) 批量创建
dept_perms = [DeptPerm(owner=serializer.instance, perm_id=x) for x in perm_ids]
DeptPerm.objects.bulk_create(dept_perms)
Expand Down Expand Up @@ -194,8 +193,7 @@ def create_group(self, group_info):
# 1) 去重
perm_ids = Perm.valid_objects.values_list('pk', flat=True)
exist_perm_ids = GroupPerm.valid_objects.filter(owner=serializer.instance).values_list('perm_id', flat=True)
for item in exist_perm_ids:
perm_ids.remove(item)
perm_ids = set(perm_ids).difference(exist_perm_ids)
# 2) 批量创建
group_perms = [GroupPerm(owner=serializer.instance, perm_id=x) for x in perm_ids]
GroupPerm.objects.bulk_create(group_perms)
Expand Down

0 comments on commit 117399d

Please sign in to comment.