Skip to content

Commit 8d03eb1

Browse files
committed
fix(patch): Merge roles: bulk insert (per chunk)
1 parent a76caac commit 8d03eb1

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

press/patches/v0_8_0/merge_press_admin_member_roles.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,21 @@ def execute():
3636
print(f"Updating {total} users")
3737
for chunk_start in range(0, total, chunk_size):
3838
chunk = users[chunk_start : chunk_start + chunk_size]
39+
now_str = frappe.utils.now()
40+
query = frappe.qb.into(HasRole).columns(
41+
"name",
42+
"creation",
43+
"modified",
44+
"modified_by",
45+
"owner",
46+
"parent",
47+
"parentfield",
48+
"parenttype",
49+
"role",
50+
)
3951
for i, user in enumerate(chunk, start=chunk_start):
40-
name = frappe.generate_hash(length=8)
41-
now_str = frappe.utils.now()
42-
frappe.qb.into(HasRole).columns(
43-
"name",
44-
"creation",
45-
"modified",
46-
"modified_by",
47-
"owner",
48-
"parent",
49-
"parentfield",
50-
"parenttype",
51-
"role",
52-
).insert(
52+
name = frappe.generate_hash(length=10)
53+
query = query.insert(
5354
name,
5455
now_str,
5556
now_str,
@@ -59,8 +60,9 @@ def execute():
5960
"roles",
6061
"User",
6162
"Press User",
62-
).run()
63+
)
6364
update_progress_bar("Updating users", i, total)
65+
query.run()
6466
frappe.db.commit()
6567

6668
# Remove old roles from all users.

0 commit comments

Comments
 (0)