Created
May 31, 2017 16:05
-
-
Save odony/df6dcbcf4668e0f9706766e33ce29657 to your computer and use it in GitHub Desktop.
Perf patch for group management on databases with many users
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git odoo/addons/base/res/res_users.py odoo/addons/base/res/res_users.py | |
index ae8863e..c3e3a41 100644 | |
--- odoo/addons/base/res/res_users.py | |
+++ odoo/addons/base/res/res_users.py | |
@@ -624,8 +624,29 @@ class GroupsImplied(models.Model): | |
if values.get('users') or values.get('implied_ids'): | |
# add all implied groups (to all users of each group) | |
for group in self: | |
- vals = {'users': zip(repeat(4), group.with_context(active_test=False).users.ids)} | |
- super(GroupsImplied, group.trans_implied_ids).write(vals) | |
+ #vals = {'users': zip(repeat(4), group.with_context(active_test=False).users.ids)} | |
+ #super(GroupsImplied, group.trans_implied_ids).write(vals) | |
+ | |
+ self._cr.execute(""" | |
+ WITH RECURSIVE group_imply(gid, hid) AS ( | |
+ SELECT gid, hid | |
+ FROM res_groups_implied_rel | |
+ UNION | |
+ SELECT i.gid, r.hid | |
+ FROM res_groups_implied_rel r | |
+ JOIN group_imply i ON (i.hid = r.gid) | |
+ ) | |
+ INSERT INTO res_groups_users_rel (gid, uid) | |
+ SELECT i.hid, r.uid | |
+ FROM group_imply i, res_groups_users_rel r | |
+ WHERE r.gid = i.gid | |
+ AND i.gid = %(gid)s | |
+ EXCEPT | |
+ SELECT r.gid, r.uid | |
+ FROM res_groups_users_rel r | |
+ JOIN group_imply i ON (r.gid = i.hid) | |
+ WHERE i.gid = %(gid)s | |
+ """, dict(gid=group.id)) | |
return res | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment