From 89be98debf3ff15b80dfc4231c7d2831e47c1da7 Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Tue, 22 Dec 2009 22:20:36 +0100 Subject: [PATCH] [FIX] multi company, speed improvement bzr revid: fp@tinyerp.com-20091222212036-oeekt3f06k5j0ize --- bin/addons/base/ir/ir_rule.py | 10 +++------- bin/osv/orm.py | 22 +++++++++++++++------- bin/sql_db.py | 1 - 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/bin/addons/base/ir/ir_rule.py b/bin/addons/base/ir/ir_rule.py index 02b87a4a77f..6cd547c3d9f 100644 --- a/bin/addons/base/ir/ir_rule.py +++ b/bin/addons/base/ir/ir_rule.py @@ -137,9 +137,9 @@ class ir_rule(osv.osv): if not (field_id or operator or operand): return {} - def domain_get2(self, cr, uid, model_name, context={}): + def domain_get(self, cr, uid, model_name, context={}): if uid == 1: - return [] + return [], [], [] cr.execute("""SELECT r.id FROM ir_rule r @@ -154,12 +154,8 @@ class ir_rule(osv.osv): dom = [] for rule in self.browse(cr, uid, ids): dom += rule.domain - return dom - - def domain_get(self, cr, uid, model_name, context={}): - dom = self.domain_get2(cr, uid, model_name, context=context) d1,d2,tables = self.pool.get(model_name)._where_calc(cr, uid, dom, active_test=False) - return ' and '.join(d1), d2, tables + return d1, d2, tables domain_get = tools.cache()(domain_get) def unlink(self, cr, uid, ids, context=None): diff --git a/bin/osv/orm.py b/bin/osv/orm.py index ae27dcece2d..94d8c23a045 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -2400,7 +2400,7 @@ class orm(orm_template): sub_ids = ids[i:i+cr.IN_MAX] if d1: cr.execute('SELECT %s FROM %s WHERE %s.id = ANY (%%s) AND %s ORDER BY %s' % \ - (','.join(fields_pre2 + [self._table + '.id']), ','.join(tables), self._table, d1, + (','.join(fields_pre2 + [self._table + '.id']), ','.join(tables), self._table, ' and '.join(d1), self._order),[sub_ids,]+d2) if not cr.rowcount == len({}.fromkeys(sub_ids)): raise except_orm(_('AccessError'), @@ -2588,14 +2588,14 @@ class orm(orm_template): d1, d2,tables = self.pool.get('ir.rule').domain_get(cr, uid, self._name, context=context) if d1: - d1 = ' AND '+d1 + d1 = ' AND '+' and '.join(d1) for i in range(0, len(ids), cr.IN_MAX): sub_ids = ids[i:i+cr.IN_MAX] str_d = string.join(('%s',)*len(sub_ids), ',') if d1: cr.execute('SELECT '+self._table+'.id FROM '+','.join(tables)+' ' \ - 'WHERE '+self._table+'.id IN ('+str_d+')'+d1, sub_ids+d2) + 'WHERE '+self._table+'.id IN ('+str_d+')'+' and '.join(d1), sub_ids+d2) if not cr.rowcount == len(sub_ids): raise except_orm(_('AccessError'), _('You try to bypass an access rule (Document type: %s).') % \ @@ -2704,14 +2704,14 @@ class orm(orm_template): d1, d2,tables = self.pool.get('ir.rule').domain_get(cr, user, self._name, context=context) if d1: - d1 = ' and '+d1 + d1 = ' and '+' and '.join(d1) for i in range(0, len(ids), cr.IN_MAX): sub_ids = ids[i:i+cr.IN_MAX] ids_str = string.join(map(str, sub_ids), ',') if d1: cr.execute('SELECT '+self._table+'.id FROM '+','.join(tables)+' ' \ - 'WHERE '+self._table+'.id IN ('+ids_str+')'+d1, d2) + 'WHERE '+self._table+'.id IN ('+ids_str+')'+' and '.join(d1), d2) if not cr.rowcount == len({}.fromkeys(sub_ids)): raise except_orm(_('AccessError'), _('You try to bypass an access rule while writing (Document type: %s).') % \ @@ -3155,13 +3155,21 @@ class orm(orm_template): if not context: context = {} # compute the where, order by, limit and offset clauses - dom = self.pool.get('ir.rule').domain_get2(cr, user, self._name, context=context) - (qu1, qu2, tables) = self._where_calc(cr, user, args+dom, context=context) + (qu1, qu2, tables) = self._where_calc(cr, user, args, context=context) + dom = self.pool.get('ir.rule').domain_get(cr, user, self._name, context=context) + print '***', dom, qu1,qu2,tables + qu1 = qu1 + dom[0] + qu2 = qu2 + dom[1] + for t in dom[2]: + if t not in tables: + tables.append(t) + if len(qu1): qu1 = ' where '+string.join(qu1, ' and ') else: qu1 = '' + if order: self._check_qorder(order) order_by = order or self._order diff --git a/bin/sql_db.py b/bin/sql_db.py index a84547b0b7c..b4ce8347f43 100644 --- a/bin/sql_db.py +++ b/bin/sql_db.py @@ -82,7 +82,6 @@ class Cursor(object): self.sql_into_log = {} self.sql_log = False self.sql_log_count = 0 - self.__closed = True # avoid the call of close() (by __del__) if an exception # is raised by any of the following initialisations self._pool = pool