Skip to content

Commit

Permalink
[IMP] connector_extension: improved resync to force to export all the…
Browse files Browse the repository at this point in the history
… dependencies once even when dependencies has binding
  • Loading branch information
KNVx authored and eantones committed Sep 6, 2024
1 parent 3bae250 commit 76da2c5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
20 changes: 20 additions & 0 deletions connector_extension/components/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 3 additions & 1 deletion connector_extension/models/binding/binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 76da2c5

Please sign in to comment.