[IMP] base_contact: performance imporovement: 'job_id' field (res.partner.contact object) was generating a lot of queries
bzr revid: olt@tinyerp.com-20100929095255-wxn4u9dfn8j0dd8z
This commit is contained in:
parent
c5de222c66
commit
960fc8e27c
|
@ -26,7 +26,7 @@ class res_partner_contact(osv.osv):
|
|||
|
||||
_name = "res.partner.contact"
|
||||
_description = "Contact"
|
||||
|
||||
|
||||
def _main_job(self, cr, uid, ids, fields, arg, context=None):
|
||||
"""
|
||||
@param self: The object pointer
|
||||
|
@ -36,12 +36,16 @@ class res_partner_contact(osv.osv):
|
|||
@fields: Get Fields
|
||||
@param context: A standard dictionary for contextual values
|
||||
@param arg: list of tuples of form [(‘name_of_the_field’, ‘operator’, value), ...]. """
|
||||
|
||||
|
||||
res = dict.fromkeys(ids, False)
|
||||
|
||||
res_partner_job_obj = self.pool.get('res.partner.job')
|
||||
all_job_ids = res_partner_job_obj.search(cr, uid, [])
|
||||
all_job_names = dict(zip(all_job_ids, res_partner_job_obj.name_get(cr, uid, all_job_ids, context=context)))
|
||||
|
||||
for contact in self.browse(cr, uid, ids, context):
|
||||
if contact.job_ids:
|
||||
res[contact.id] = contact.job_ids[0].name_get()[0]
|
||||
res[contact.id] = all_job_names.get(contact.job_ids[0].id, False)
|
||||
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
|
@ -61,7 +65,7 @@ class res_partner_contact(osv.osv):
|
|||
'function': fields.related('job_ids', 'function', type='char', \
|
||||
string='Main Function'),
|
||||
'job_id': fields.function(_main_job, method=True, type='many2one',\
|
||||
relation='res.partner.job', string='Main Job', store=True),
|
||||
relation='res.partner.job', string='Main Job'),
|
||||
'email': fields.char('E-Mail', size=240),
|
||||
'comment': fields.text('Notes', translate=True),
|
||||
'photo': fields.binary('Image'),
|
||||
|
@ -138,8 +142,7 @@ class res_partner_address(osv.osv):
|
|||
res_partner_address()
|
||||
|
||||
class res_partner_job(osv.osv):
|
||||
|
||||
def name_get(self, cr, uid, ids, context={}):
|
||||
def name_get(self, cr, uid, ids, context=None):
|
||||
"""
|
||||
@param self: The object pointer
|
||||
@param cr: the current row, from the database cursor,
|
||||
|
@ -147,12 +150,15 @@ class res_partner_job(osv.osv):
|
|||
@param ids: List of partner address’s IDs
|
||||
@param context: A standard dictionary for contextual values
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
|
||||
if not len(ids):
|
||||
if not ids:
|
||||
return []
|
||||
res = []
|
||||
|
||||
jobs = self.browse(cr, uid, ids)
|
||||
|
||||
contact_ids = [rec.contact_id.id for rec in jobs]
|
||||
contact_names = dict(self.pool.get('res.partner.contact').name_get(cr, uid, contact_ids, context=context))
|
||||
|
||||
|
@ -160,6 +166,7 @@ class res_partner_job(osv.osv):
|
|||
function_name = r.function
|
||||
funct = function_name and (", " + function_name) or ""
|
||||
res.append((r.id, contact_names.get(r.contact_id.id, '') + funct))
|
||||
|
||||
return res
|
||||
|
||||
def search(self, cr, user, args, offset=0, limit=None, order=None, context=None, count=False):
|
||||
|
|
Loading…
Reference in New Issue