feat: Optimize initial sync logic and remove redundant rowId updates in sync process

This commit is contained in:
2026-02-07 22:38:53 +00:00
parent 7a7a322389
commit 709456301c
3 changed files with 466 additions and 38 deletions

View File

@@ -204,35 +204,6 @@ async def handle_update(entity_id, betnr, espo_entity, espocrm, advoware, sync_u
context.logger.info(f"⏱️ Vergleich: {comparison}")
# SPECIAL: Wenn LastSync null → immer von EspoCRM syncen (initial sync)
if not espo_entity.get('advowareLastSync'):
context.logger.info(f"📤 Initial Sync → EspoCRM STAMMDATEN zu Advoware")
# OPTIMIERT: Use merge utility (reduces code duplication)
merged_data = sync_utils.merge_for_advoware_put(advo_entity, espo_entity, mapper)
put_result = await advoware.api_call(
f'api/v1/advonet/Beteiligte/{betnr}',
method='PUT',
data=merged_data
)
# Extrahiere neue rowId aus PUT Response (spart extra GET!)
new_rowid = None
if isinstance(put_result, list) and len(put_result) > 0:
new_rowid = put_result[0].get('rowId')
elif isinstance(put_result, dict):
new_rowid = put_result.get('rowId')
# Speichere neue rowId für zukünftige Vergleiche
await sync_utils.release_sync_lock(
entity_id,
'clean',
extra_fields={'advowareRowId': new_rowid}
)
context.logger.info(f"✅ Advoware aktualisiert (initial sync), neue rowId: {new_rowid[:20] if new_rowid else 'N/A'}...")
return
# KEIN SYNC NÖTIG
if comparison == 'no_change':
context.logger.info(f"✅ Keine Änderungen, Sync übersprungen")
@@ -259,19 +230,13 @@ async def handle_update(entity_id, betnr, espo_entity, espocrm, advoware, sync_u
elif isinstance(put_result, dict):
new_rowid = put_result.get('rowId')
# Schreibe neue rowId zurück nach EspoCRM
if new_rowid:
await espocrm.update_entity('CBeteiligte', entity_id, {
'advowareRowId': new_rowid
})
context.logger.info(f"📝 rowId in EspoCRM aktualisiert: {new_rowid[:20]}...")
# Release Lock + Update rowId in einem Call (effizienter!)
await sync_utils.release_sync_lock(
entity_id,
'clean',
extra_fields={'advowareRowId': new_rowid}
)
context.logger.info(f"✅ Advoware aktualisiert, neue rowId: {new_rowid[:20] if new_rowid else 'N/A'}...")
context.logger.info(f"✅ Advoware aktualisiert, rowId in EspoCRM geschrieben: {new_rowid[:20] if new_rowid else 'N/A'}...")
# ADVOWARE NEUER → Update EspoCRM
elif comparison == 'advoware_newer':