Skip to content

Commit cddd422

Browse files
committed
refactor: use dGetArrayElements in replaceActivityRecursive to reduce duplication
1 parent 767b9f8 commit cddd422

1 file changed

Lines changed: 4 additions & 15 deletions

File tree

mdl/backend/mpr/workflow_mutator.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -579,25 +579,14 @@ func (m *mprWorkflowMutator) replaceActivity(updated bson.D) {
579579
}
580580

581581
func replaceActivityRecursive(flow bson.D, actID string, updated bson.D) bool {
582-
activitiesVal := dGet(flow, "Activities")
583-
arr := toBsonA(activitiesVal)
584-
if len(arr) == 0 {
585-
return false
586-
}
587-
// Skip the int32 type marker at index 0 if present.
588-
start := 0
589-
if _, ok := arr[0].(int32); ok {
590-
start = 1
591-
} else if _, ok := arr[0].(int); ok {
592-
start = 1
593-
}
594-
for i := start; i < len(arr); i++ {
595-
actDoc, ok := arr[i].(bson.D)
582+
elements := dGetArrayElements(dGet(flow, "Activities"))
583+
for i, elem := range elements {
584+
actDoc, ok := elem.(bson.D)
596585
if !ok {
597586
continue
598587
}
599588
if extractBinaryIDFromDoc(dGet(actDoc, "$ID")) == actID {
600-
arr[i] = updated
589+
elements[i] = updated
601590
return true
602591
}
603592
for _, nestedFlow := range getNestedFlows(actDoc) {

0 commit comments

Comments
 (0)