@@ -445,6 +445,7 @@ func ModelSync(appCtx *cli.Context) error {
445445 deleteMode := appCtx .Bool ("delete" )
446446 dryRunMode := appCtx .Bool ("dry-run" )
447447 verboseMode := appCtx .Bool ("verbose" )
448+ maxConcurrency := appCtx .Int ("max-concurrency" )
448449 printMode := dryRunMode || verboseMode
449450
450451 marshaller , err := marshallerForFormat (appCtx .String ("format" ))
@@ -545,7 +546,7 @@ func ModelSync(appCtx *cli.Context) error {
545546 errs := []error {}
546547
547548 // Delete relationships before deleting entities.
548- deleteRelationshipsPool := pool .New ().WithErrors ()
549+ deleteRelationshipsPool := pool .New ().WithErrors (). WithMaxGoroutines ( maxConcurrency )
549550 if deleteMode {
550551 relationshipsToBeDeleted := remoteRelationshipKeys .Difference (localRelationshipKeys )
551552 for relationship := range relationshipsToBeDeleted .Iter () {
@@ -568,7 +569,7 @@ func ModelSync(appCtx *cli.Context) error {
568569 errs = append (errs , deleteRelationshipsPool .Wait ())
569570
570571 // Update entities.
571- updatePool := pool .New ().WithErrors ()
572+ updatePool := pool .New ().WithErrors (). WithMaxGoroutines ( maxConcurrency )
572573 entitiesInCommon := localEntityKeys .Intersect (remoteEntityKeys )
573574 for entity := range entitiesInCommon .Iter () {
574575 updatePool .Go (func () error {
@@ -589,12 +590,11 @@ func ModelSync(appCtx *cli.Context) error {
589590 }
590591
591592 // Maybe delete entities (and prune collaterally deleted relationships)
592- deleteEntitiesPool := pool .New ().WithErrors ()
593593 if deleteMode {
594594 entitiesToBeDeleted := remoteEntityKeys .Difference (localEntityKeys )
595595
596596 for entity := range entitiesToBeDeleted .Iter () {
597- deleteEntitiesPool .Go (func () error {
597+ updatePool .Go (func () error {
598598 if printMode {
599599 fmt .Printf ("delete entity: %s\n " , entity )
600600 }
@@ -613,10 +613,9 @@ func ModelSync(appCtx *cli.Context) error {
613613 }
614614
615615 errs = append (errs , updatePool .Wait ())
616- errs = append (errs , deleteEntitiesPool .Wait ())
617616
618617 // Add entities.
619- addEntitiesPool := pool .New ().WithErrors ()
618+ addEntitiesPool := pool .New ().WithErrors (). WithMaxGoroutines ( maxConcurrency )
620619 entitiesToBeAdded := localEntityKeys .Difference (remoteEntityKeys )
621620 for entity := range entitiesToBeAdded .Iter () {
622621 addEntitiesPool .Go (func () error {
@@ -637,7 +636,7 @@ func ModelSync(appCtx *cli.Context) error {
637636 errs = append (errs , addEntitiesPool .Wait ())
638637
639638 // Add relationships.
640- addRelationshipsPool := pool .New ().WithErrors ()
639+ addRelationshipsPool := pool .New ().WithErrors (). WithMaxGoroutines ( maxConcurrency )
641640 relationshipsToBeAdded := localRelationshipKeys .Difference (remoteRelationshipKeys )
642641 for relationship := range relationshipsToBeAdded .Iter () {
643642 addRelationshipsPool .Go (func () error {
0 commit comments