[FIX] Speed improvement properties
authorFabien Pinckaers <fp@tinyerp.com>
Sat, 18 Sep 2010 10:19:58 +0000 (12:19 +0200)
committerFabien Pinckaers <fp@tinyerp.com>
Sat, 18 Sep 2010 10:19:58 +0000 (12:19 +0200)
bzr revid: fp@tinyerp.com-20100918101958-jj3vpqzy6lbvv0yk

bin/addons/base/res/ir_property.py
bin/osv/fields.py

index 8dcd01c..78c5f6c 100644 (file)
@@ -135,15 +135,7 @@ class ir_property(osv.osv):
     def create(self, cr, uid, values, context=None):
         return super(ir_property, self).create(cr, uid, self._update_values(cr, uid, None, values), context=context)
 
-    def get_by_id(self, cr, uid, record_ids, context=None):
-        if isinstance(record_ids, (int, long)):
-            record_ids = [record_ids]
-
-        if not record_ids:
-            return False
-
-        record = self.browse(cr, uid, record_ids[0], context=context)
-
+    def get_by_record(self, cr, uid, record, context=None):
         if record.type in ('char', 'text'):
             return record.value_text
         elif record.type == 'float':
@@ -155,14 +147,13 @@ class ir_property(osv.osv):
         elif record.type == 'binary':
             return record.value_binary
         elif record.type == 'many2one':
-            return record.value_reference
+            return record.value_reference.id
         elif record.type == 'datetime':
             return record.value_datetime
         elif record.type == 'date':
             if not record.value_datetime:
                 return False
             return time.strftime('%Y-%m-%d', time.strptime(record.value_datetime, '%Y-%m-%d %H:%M:%S'))
-
         return False
 
     def get(self, cr, uid, name, model, res_id=False, context={}):
@@ -170,7 +161,8 @@ class ir_property(osv.osv):
         if domain is not None:
             domain = [('res_id', '=', res_id)] + domain
             nid = self.search(cr, uid, domain, context=context)
-            return self.get_by_id(cr, uid, nid, context=context)
+            record = self.browse(cr, uid, nid, context=context)
+            return self.get_by_record(cr, uid, record, context=context)
         return False
 
     def _get_domain_default(self, cr, uid, prop_name, model, context=None):
index 97a6f13..e9ea6f9 100644 (file)
@@ -881,19 +881,17 @@ class serialized(_column):
         super(serialized, self).__init__(string=string, **args)
 
 
+# TODO: review completly this class for speed improvement
 class property(function):
 
     def _get_default(self, obj, cr, uid, prop_name, context=None):
-        from orm import browse_record
         prop = obj.pool.get('ir.property')
         domain = prop._get_domain_default(cr, uid, prop_name, obj._name, context)
         ids = prop.search(cr, uid, domain, order='company_id', context=context)
         if not ids:
             return False
-
-        default_value = prop.get_by_id(cr, uid, ids, context=context)
-        if isinstance(default_value, browse_record):
-            return default_value.id
+        prop_rec = prop.browse(cr, uid, ids[0], context=context)
+        default_value = prop.get_by_record(cr, uid, prop_rec, context=context)
         return default_value or False
 
     def _get_by_id(self, obj, cr, uid, prop_name, ids, context=None):
@@ -938,24 +936,24 @@ class property(function):
 
 
     def _fnct_read(self, obj, cr, uid, ids, prop_name, obj_dest, context=None):
-        from orm import browse_record
+        #from orm import browse_record
         properties = obj.pool.get('ir.property')
 
+        domain = properties._get_domain(cr, uid, prop_name, obj._name, context) or []
+        domain += [('res_id','in', [obj._name + ',' + str(oid) for oid in  ids])]
+        nids = properties.search(cr, uid, domain, context=context)
+
         default_val = self._get_default(obj, cr, uid, prop_name, context)
 
-        nids = self._get_by_id(obj, cr, uid, prop_name, ids, context)
+        #nids = self._get_by_id(obj, cr, uid, prop_name, ids, context)
 
         res = {}
         for id in ids:
             res[id] = default_val
-        for prop in properties.browse(cr, uid, nids):
-            value = prop.get_by_id(context=context)
-            if isinstance(value, browse_record):
-                if not value.exists():
-                    cr.execute('DELETE FROM ir_property WHERE id=%s', (prop.id,))
-                    continue
-                value = value.id
+        for prop in properties.browse(cr, uid, nids, context=context):
+            value = properties.get_by_record(cr, uid, prop, context=context)
             res[prop.res_id.id] = value or False
+
         return res