Skip to content

Commit 79d5b58

Browse files
committed
Avoid using d.Get("task") for each task in appflow_flow
The original implementation called d.Get("task") for each task's source_fields attribute. As a result, for each task, d.Get("task") is called - which turns out to be expensive. For example for ~350 tasks, this seemed to take about 15 minutes. Profiling for this original behavoir can be seen in the PR. This change introduces a new single_task_flag attribute, which is computed once during the read operation and this is used to determine if a single task is present (which is what the original result of d.Get("task") was used for. From local testing of the use-case, this completely fixes the slow-down
1 parent 854cdb7 commit 79d5b58

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

internal/service/appflow/flow.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,16 +1208,12 @@ func resourceFlow() *schema.Resource {
12081208
ValidateFunc: validation.StringLenBetween(0, 2048),
12091209
},
12101210
DiffSuppressFunc: func(k, oldValue, newValue string, d *schema.ResourceData) bool {
1211-
if v, ok := d.Get("task").(*schema.Set); ok && v.Len() == 1 {
1212-
if tl, ok := v.List()[0].(map[string]any); ok && len(tl) > 0 {
1213-
if sf, ok := tl["source_fields"].([]any); ok && len(sf) == 1 {
1214-
if sf[0] == "" {
1215-
return oldValue == "0" && newValue == "1"
1216-
}
1217-
}
1218-
}
1211+
marker, ok := d.Get("single_task_flag").(bool)
1212+
if !ok || !marker {
1213+
return false
12191214
}
1220-
return false
1215+
1216+
return oldValue == "0" && newValue == "1"
12211217
},
12221218
},
12231219
"task_properties": {
@@ -1236,6 +1232,16 @@ func resourceFlow() *schema.Resource {
12361232
},
12371233
},
12381234
},
1235+
"single_task_flag": {
1236+
Type: schema.TypeBool,
1237+
Computed: true,
1238+
Optional: true,
1239+
ForceNew: false,
1240+
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
1241+
// Ignore internal field
1242+
return true
1243+
},
1244+
},
12391245
"trigger_config": {
12401246
Type: schema.TypeList,
12411247
Required: true,
@@ -1415,9 +1421,13 @@ func resourceFlowRead(ctx context.Context, d *schema.ResourceData, meta any) dia
14151421
} else {
14161422
d.Set("source_flow_config", nil)
14171423
}
1418-
if err := d.Set("task", flattenTasks(output.Tasks)); err != nil {
1424+
tasks := flattenTasks(output.Tasks)
1425+
if err := d.Set("task", tasks); err != nil {
14191426
return sdkdiag.AppendErrorf(diags, "setting task: %s", err)
14201427
}
1428+
if err := d.Set("single_task_flag", len(tasks) == 1); err != nil {
1429+
return sdkdiag.AppendErrorf(diags, "setting single_task_flag: %s", err)
1430+
}
14211431
if output.TriggerConfig != nil {
14221432
if err := d.Set("trigger_config", []any{flattenTriggerConfig(output.TriggerConfig)}); err != nil {
14231433
return sdkdiag.AppendErrorf(diags, "setting trigger_config: %s", err)

0 commit comments

Comments
 (0)