Skip to content

Commit

Permalink
tune migration performance (#2637)
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvin-muchiri authored Jul 8, 2024
1 parent cb2c06e commit 13904bc
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@ def add_project_entitylist_perm(apps, schema_editor):
eta = project_qs.count()

for project in project_qs.iterator(chunk_size=200):
processed_users = set()
project_user_obj_perm_qs = project.projectuserobjectpermission_set.all()
# Owners and Managers have the `add_project` permission
project_user_obj_perm_qs = project.projectuserobjectpermission_set.filter(
permission__codename="add_project"
)
project_group_obj_perm_qs = project.projectgroupobjectpermission_set.filter(
permission__codename="add_project"
)

for perm in project_user_obj_perm_qs.iterator(chunk_size=100):
user = perm.user
_ = assign_perm("add_project_entitylist", perm.user, project)

if user.pk not in processed_users and user.has_perm("add_project", project):
_ = assign_perm("add_project_entitylist", user, project)
processed_users.add(user.pk)
for perm in project_group_obj_perm_qs.iterator(chunk_size=100):
_ = assign_perm("add_project_entitylist", perm.group, project)

eta -= 1
print("eta", eta)
Expand Down

0 comments on commit 13904bc

Please sign in to comment.