# HG changeset patch # User Sylvain Thénault # Date 1302783526 -7200 # Node ID 7a58581d842c17fe0de519b9ab386869c4c476fd # Parent fcb8932082a5dcfcfaf23a7d5e96feffc29c6b6c [entity] create_entity/cw_instantiate should initialize entity's cache to avoid later queries diff -r fcb8932082a5 -r 7a58581d842c entity.py --- a/entity.py Thu Apr 14 14:18:44 2011 +0200 +++ b/entity.py Thu Apr 14 14:18:46 2011 +0200 @@ -266,6 +266,7 @@ restrictions = set() pending_relations = [] eschema = cls.e_schema + cache = {} for attr, value in kwargs.items(): if attr.startswith('reverse_'): attr = attr[len('reverse_'):] @@ -274,7 +275,9 @@ role = 'subject' assert eschema.has_relation(attr, role) rschema = eschema.subjrels[attr] if role == 'subject' else eschema.objrels[attr] - if not rschema.final and isinstance(value, (tuple, list, set, frozenset)): + if rschema.final: + cache[attr] = value # XXX what if value is processed in pre add hook (eg timeseries)? + elif isinstance(value, (tuple, list, set, frozenset)): if len(value) == 1: value = iter(value).next() else: @@ -299,6 +302,7 @@ if restrictions: rql = '%s WHERE %s' % (rql, ', '.join(restrictions)) created = execute(rql, kwargs).get_entity(0, 0) + created.cw_attr_cache.update(cache) for attr, values in pending_relations: if attr.startswith('reverse_'): restr = 'Y %s X' % attr[len('reverse_'):]