From 5f12e244f6e57b8edb56788147774150e2ae134d Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Thu, 10 Jan 2019 13:48:40 +0000 Subject: [PATCH] [IMP] base: compute implied groups in SQL SQL improve the speed of the implied group VS the orm version. closes odoo/odoo#30108 --- odoo/addons/base/res/res_users.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/odoo/addons/base/res/res_users.py b/odoo/addons/base/res/res_users.py index 8c7194d4279ed..12b31da37ec24 100644 --- a/odoo/addons/base/res/res_users.py +++ b/odoo/addons/base/res/res_users.py @@ -657,8 +657,26 @@ def write(self, values): 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) + 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