From f23546a7c0f1871041a5633de08db43db7f9f810 Mon Sep 17 00:00:00 2001 From: "olt@tinyerp.com" <> Date: Thu, 23 Sep 2010 16:23:34 +0200 Subject: [PATCH] [IMP] performance improvement: using a map (from 1 sql query) instead of queries in loop bzr revid: olt@tinyerp.com-20100923142334-us9n6pdza0f5i25b --- addons/hr_timesheet_invoice/hr_timesheet_invoice.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/addons/hr_timesheet_invoice/hr_timesheet_invoice.py b/addons/hr_timesheet_invoice/hr_timesheet_invoice.py index cc6137313b1..ed1c8394de1 100644 --- a/addons/hr_timesheet_invoice/hr_timesheet_invoice.py +++ b/addons/hr_timesheet_invoice/hr_timesheet_invoice.py @@ -44,17 +44,22 @@ class account_analytic_account(osv.osv): if context is None: context = {} res = {} + + cr.execute('select account_id as account_id, l.invoice_id from hr_analytic_timesheet h left join account_analytic_line l on (h.line_id=l.id)') + account_to_invoice_map = {} + for rec in cr.dictfetchall(): + account_to_invoice_map.setdefault(rec['account_id'], []).append(rec['invoice_id']) + for account in self.browse(cr, uid, ids, context=context): invoiced = {} - cr.execute('select distinct(l.invoice_id) from hr_analytic_timesheet h left join account_analytic_line l on (h.line_id=l.id) where account_id=%s', (account.id,)) - invoice_ids = filter(None, map(lambda x: x[0], cr.fetchall())) + invoice_ids = filter(None, list(set(account_to_invoice_map.get(account.id, [])))) for invoice in obj_invoice.browse(cr, uid, invoice_ids, context=context): res.setdefault(account.id, 0.0) res[account.id] += invoice.amount_untaxed for id in ids: res[id] = round(res.get(id, 0.0),2) - return res + return res _inherit = "account.analytic.account" _columns = {