# HG changeset patch # User Sylvain Thénault # Date 1264780489 -3600 # Node ID 899b426087ab8a8a3b5b89028f5ea04e7c02af72 # Parent e4f921a6870389d1bf72ee253107b92a1c27455f [entity] small optimization: once an entity has been completed, don't redo it (for nothing) diff -r e4f921a68703 -r 899b426087ab entity.py --- a/entity.py Fri Jan 29 16:53:52 2010 +0100 +++ b/entity.py Fri Jan 29 16:54:49 2010 +0100 @@ -573,6 +573,7 @@ continue yield attr + _cw_completed = False def complete(self, attributes=None, skip_bytes=True): """complete this entity by adding missing attributes (i.e. query the repository to fill the entity) @@ -582,6 +583,10 @@ if true, attribute of type Bytes won't be considered """ assert self.has_eid() + if self._cw_completed: + return + if attributes is None: + self._cw_completed = True varmaker = rqlvar_maker() V = varmaker.next() rql = ['WHERE %s eid %%(x)s' % V] @@ -864,14 +869,23 @@ self._related_cache.pop('%s_%s' % (rtype, role), None) def clear_all_caches(self): + """flush all caches on this entity. Further attributes/relations access + will triggers new database queries to get back values. + + If you use custom caches on your entity class (take care to @cached!), + you should override this method to clear them as well. + """ + # clear attributes cache haseid = 'eid' in self + self._cw_completed = False self.clear() - for rschema, _, role in self.e_schema.relation_definitions(): - self.clear_related_cache(rschema.type, role) # set eid if it was in, else we may get nasty error while editing this # entity if it's bound to a repo session if haseid: self['eid'] = self.eid + # clear relations cache + for rschema, _, role in self.e_schema.relation_definitions(): + self.clear_related_cache(rschema.type, role) # raw edition utilities ###################################################