diff --git a/connector-superoffice/worker.py b/connector-superoffice/worker.py index 6e9f7b79..c788afc9 100644 --- a/connector-superoffice/worker.py +++ b/connector-superoffice/worker.py @@ -52,6 +52,47 @@ def process_job(job, so_client: SuperOfficeClient): except (ValueError, TypeError): pass + # 0b. Noise Reduction: Filter irrelevant field changes + # Only re-process if core data (Name, Website) or UDFs (Vertical) changed. + if job['event_type'] == 'contact.changed': + changes = payload.get('Changes', []) + # Normalize to lower case for comparison + changes_lower = [str(c).lower() for c in changes] + + # Fields that trigger a re-analysis + relevant_fields = [ + 'name', # Company Name change -> Full Re-Scan + 'urladdress', # Website change -> Full Re-Scan + 'urls', # Website array change + 'orgnr', # VAT/Register ID change + 'userdef_id', # UDFs (Verticals, etc.) changed + 'country_id' # Country change + ] + + # Check if ANY relevant field is in the changes list + is_relevant = any(field in changes_lower for field in relevant_fields) + + if not is_relevant: + logger.info(f"⏭️ Skipping 'contact.changed': No relevant fields changed. (Changes: {changes})") + return "SUCCESS" + + if job['event_type'] == 'person.changed': + changes = payload.get('Changes', []) + changes_lower = [str(c).lower() for c in changes] + + relevant_person_fields = [ + 'jobtitle', # Job Title change + 'title', # Alternative title field + 'position_id', # Standard Position/Role dropdown + 'userdef_id' # UDFs (MA Status, Campaign, etc.) + ] + + is_relevant = any(field in changes_lower for field in relevant_person_fields) + + if not is_relevant: + logger.info(f"⏭️ Skipping 'person.changed': No relevant fields changed. (Changes: {changes})") + return "SUCCESS" + # 1. Extract IDs Early person_id = None contact_id = None