diff --git a/connector_extension/components/exporter.py b/connector_extension/components/exporter.py index 3df134b7c..c9ceb5792 100644 --- a/connector_extension/components/exporter.py +++ b/connector_extension/components/exporter.py @@ -193,6 +193,26 @@ def _export_dependency( pass extra values for this binding :type binding_extra_vals: dict """ + if not always and relation.env.context.get("resync_export", False): + # This is an optimization to avoid exporting + # the same record multiple times on resync + if "resync_exported_dependencies" not in self.env.context: + self.env.context = { + **self.env.context, + "resync_exported_dependencies": {}, + } + + resync_model_ids = self.env.context["resync_exported_dependencies"] + model_name = relation._name + + if model_name not in resync_model_ids: + resync_model_ids[model_name] = [relation.id] + else: + if relation.id in resync_model_ids[model_name]: + return + resync_model_ids[model_name].append(relation.id) + always = True + exporter = self.component(usage=component_usage, model_name=binding_model) exporter.run(relation, always=always) diff --git a/connector_extension/models/binding/binding.py b/connector_extension/models/binding/binding.py index ef9434dde..7f1108317 100644 --- a/connector_extension/models/binding/binding.py +++ b/connector_extension/models/binding/binding.py @@ -101,7 +101,9 @@ def resync_export(self): for record in self: with record.backend_id.work_on(record._name) as work: binder = work.component(usage="binder") - relation = binder.unwrap_binding(record) + relation = binder.unwrap_binding(record).with_context( + resync_export=True + ) func = record.export_record if record.env.context.get("connector_delay"): func = func.with_delay