# HG changeset patch # User Sylvain Thénault # Date 1318334158 -7200 # Node ID 2250a60a76535254adaeed3c1355a36d051a1d08 # Parent 60068dc834571a28b29487a667ae3d4fe7a5be58# Parent b25dda2214a2bf5aa96fa9faac1412950bbd390a backport stable diff -r 60068dc83457 -r 2250a60a7653 server/sources/datafeed.py --- a/server/sources/datafeed.py Tue Oct 11 11:00:24 2011 +0200 +++ b/server/sources/datafeed.py Tue Oct 11 13:55:58 2011 +0200 @@ -151,10 +151,10 @@ # XXX race condition until WHERE of SET queries is executed using # 'SELECT FOR UPDATE' now = datetime.utcnow() - if not session.execute('SET X in_synchronizaton %(now)s WHERE X eid %(x)s, X synchronizing NULL OR X synchronizing < %(maxdt)s', - {'x': self.eid, - 'now': now, - 'maxdt': now - self.max_lock_lifetime}): + if not session.execute( + 'SET X in_synchronization %(now)s WHERE X eid %(x)s, ' + 'X in_synchronization NULL OR X in_synchronization < %(maxdt)s', + {'x': self.eid, 'now': now, 'maxdt': now - self.max_lock_lifetime}): self.error('concurrent synchronization detected, skip pull') session.commit(free_cnxset=False) return False @@ -163,7 +163,7 @@ def release_synchronization_lock(self, session): session.set_cnxset() - session.execute('SET X synchronizing None WHERE X eid %(x)s', + session.execute('SET X in_synchronization NULL WHERE X eid %(x)s', {'x': self.eid}) session.commit() diff -r 60068dc83457 -r 2250a60a7653 sobjects/parsers.py --- a/sobjects/parsers.py Tue Oct 11 11:00:24 2011 +0200 +++ b/sobjects/parsers.py Tue Oct 11 13:55:58 2011 +0200 @@ -72,7 +72,7 @@ typeddict = {} for rschema in eschema.subject_relations(): if rschema.final and rschema in stringdict: - if rschema == 'eid': + if rschema in ('eid', 'cwuri', 'cwtype', 'cwsource'): continue attrtype = eschema.destination(rschema) value = stringdict[rschema] @@ -200,8 +200,8 @@ * `rels` is for relations and structured as {role: {relation: [(related item, related rels)...]} """ - entity = self.extid2entity(str(item.pop('cwuri')), item.pop('cwtype'), - cwsource=item.pop('cwsource'), item=item) + entity = self.extid2entity(str(item['cwuri']), item['cwtype'], + cwsource=item['cwsource'], item=item) if entity is None: return None if entity.eid in self._processed_entities: @@ -209,10 +209,16 @@ self._processed_entities.add(entity.eid) if not (self.created_during_pull(entity) or self.updated_during_pull(entity)): self.notify_updated(entity) - item.pop('eid') - # XXX check modification date attrs = extract_typed_attrs(entity.e_schema, item) - entity.set_attributes(**attrs) + # check modification date and compare attribute values to only + # update what's actually needed + entity.complete(tuple(attrs)) + mdate = attrs.get('modification_date') + if not mdate or mdate > entity.modification_date: + attrs = dict( (k, v) for k, v in attrs.iteritems() + if v != getattr(entity, k)) + if attrs: + entity.set_attributes(**attrs) self.process_relations(entity, rels) return entity