Skip to content

Commit d420961

Browse files
petr-mullerclaude
andcommitted
fix(private-org-sync): run source and destination ls-remote in parallel
Instead of querying source and destination branch heads sequentially, run both ls-remote calls concurrently using goroutines. This saves one network round-trip per repo. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent bc077f9 commit d420961

1 file changed

Lines changed: 27 additions & 8 deletions

File tree

cmd/private-org-sync/main.go

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ func main() {
712712
continue
713713
}
714714

715-
// ls-remote destination once per repo
715+
// ls-remote source and destination in parallel
716716
destUrlRaw := fmt.Sprintf("%s/%s/%s", syncer.prefix, o.targetOrg, dstRepo)
717717
destUrl, err := url.Parse(destUrlRaw)
718718
if err != nil {
@@ -726,8 +726,27 @@ func main() {
726726
destUrl.User = url.User(syncer.token)
727727
}
728728

729-
dstHeads, err := getRemoteBranchHeads(repoLogger, syncer.git, gitDir, destUrl.String())
730-
if err != nil {
729+
srcRemote := fmt.Sprintf("%s-%s", key.org, key.repo)
730+
731+
type lsRemoteResult struct {
732+
heads RemoteBranchHeads
733+
err error
734+
}
735+
dstResult := make(chan lsRemoteResult, 1)
736+
srcResult := make(chan lsRemoteResult, 1)
737+
go func() {
738+
heads, err := getRemoteBranchHeads(repoLogger, syncer.git, gitDir, destUrl.String())
739+
dstResult <- lsRemoteResult{heads, err}
740+
}()
741+
go func() {
742+
heads, err := getRemoteBranchHeads(repoLogger, withRetryOnNonzero(syncer.git, 5), gitDir, srcRemote)
743+
srcResult <- lsRemoteResult{heads, err}
744+
}()
745+
746+
dst := <-dstResult
747+
src := <-srcResult
748+
749+
if dst.err != nil {
731750
message := "destination repository does not exist or we cannot access it"
732751
if syncer.failOnNonexistentDst {
733752
repoLogger.Errorf("%s", message)
@@ -740,17 +759,17 @@ func main() {
740759
continue
741760
}
742761

743-
// ls-remote source once per repo
744-
srcRemote := fmt.Sprintf("%s-%s", key.org, key.repo)
745-
srcHeads, err := getRemoteBranchHeads(repoLogger, withRetryOnNonzero(syncer.git, 5), gitDir, srcRemote)
746-
if err != nil {
747-
repoLogger.WithError(err).Error("Failed to determine branch HEADs in source")
762+
if src.err != nil {
763+
repoLogger.WithError(src.err).Error("Failed to determine branch HEADs in source")
748764
for _, source := range branches {
749765
errs = append(errs, fmt.Errorf("%s: failed to determine branch HEADs in source", source.String()))
750766
}
751767
continue
752768
}
753769

770+
dstHeads := dst.heads
771+
srcHeads := src.heads
772+
754773
for _, source := range branches {
755774
syncer.logger = config.LoggerForInfo(config.Info{
756775
Metadata: api.Metadata{

0 commit comments

Comments
 (0)