[IMP] mail: speed up filtering of mail.group menus
Replacing the browse+search speeds up the filtering 50x, which is significant for a method that may be called on most page loads as soon as the user is logged in.
This commit is contained in:
parent
6e6f12144d
commit
68aa292f0a
|
@ -19,11 +19,9 @@
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
from openerp import SUPERUSER_ID
|
|
||||||
from openerp.osv import osv
|
from openerp.osv import osv
|
||||||
from openerp.osv import fields
|
from openerp.osv import fields
|
||||||
|
|
||||||
|
|
||||||
class ir_ui_menu(osv.osv):
|
class ir_ui_menu(osv.osv):
|
||||||
""" Override of ir.ui.menu class. When adding mail_thread module, each
|
""" Override of ir.ui.menu class. When adding mail_thread module, each
|
||||||
new mail.group will create a menu entry. This overrides checks that
|
new mail.group will create a menu entry. This overrides checks that
|
||||||
|
@ -38,21 +36,22 @@ class ir_ui_menu(osv.osv):
|
||||||
}
|
}
|
||||||
|
|
||||||
def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):
|
def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):
|
||||||
""" Override to take off menu entries (mail.group) the user is not
|
""" Remove mail.group menu entries when the user is not a follower."""
|
||||||
following. Access are done using SUPERUSER_ID to avoid access
|
ids = super(ir_ui_menu, self).search(cr, uid, args, offset=offset,
|
||||||
rights issues for an internal back-end algorithm. """
|
limit=limit, order=order,
|
||||||
ids = super(ir_ui_menu, self).search(cr, uid, args, offset=offset, limit=limit, order=order, context=context, count=False)
|
context=context, count=False)
|
||||||
partner_id = self.pool.get('res.users').read(cr, uid, [uid], ['partner_id'], context=context)[0]['partner_id'][0]
|
if ids:
|
||||||
follower_obj = self.pool.get('mail.followers')
|
cr.execute("""
|
||||||
for menu in self.browse(cr, uid, ids, context=context):
|
SELECT id FROM ir_ui_menu m
|
||||||
if menu.mail_group_id:
|
WHERE m.mail_group_id IS NULL OR EXISTS (
|
||||||
sub_ids = follower_obj.search(cr, SUPERUSER_ID, [
|
SELECT 1 FROM mail_followers
|
||||||
('partner_id', '=', partner_id),
|
WHERE res_model = 'mail.group' AND res_id = m.mail_group_id
|
||||||
('res_model', '=', 'mail.group'),
|
AND partner_id = (SELECT partner_id FROM res_users WHERE id = %s)
|
||||||
('res_id', '=', menu.mail_group_id.id)
|
) AND id in %s
|
||||||
], context=context)
|
""", (uid, tuple(ids)))
|
||||||
if not sub_ids:
|
# Preserve original search order
|
||||||
ids.remove(menu.id)
|
visible_ids = set(x[0] for x in cr.fetchall())
|
||||||
|
ids = [i for i in ids if i in visible_ids]
|
||||||
if count:
|
if count:
|
||||||
return len(ids)
|
return len(ids)
|
||||||
return ids
|
return ids
|
||||||
|
|
Loading…
Reference in New Issue