From 7c09ce38719ddf44e775783a7dfea0f3e6d4071c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luka=20Marku=C5=A1i=C4=87?= Date: Fri, 29 Jul 2022 22:53:05 +0200 Subject: [PATCH] Parallelize fetching current branch --- pkg/gui/recent_repos_panel.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/pkg/gui/recent_repos_panel.go b/pkg/gui/recent_repos_panel.go index 94161030d..636c01b1e 100644 --- a/pkg/gui/recent_repos_panel.go +++ b/pkg/gui/recent_repos_panel.go @@ -5,6 +5,7 @@ import ( "os" "path/filepath" "strings" + "sync" "github.com/jesseduffield/generics/slices" "github.com/jesseduffield/lazygit/pkg/commands" @@ -27,10 +28,24 @@ func (gui *Gui) handleCreateRecentReposMenu() error { // we skip the first one because we're currently in it recentRepoPaths := gui.c.GetAppState().RecentRepos[1:] + currentBranches := sync.Map{} + + wg := sync.WaitGroup{} + wg.Add(len(recentRepoPaths)) + + for _, path := range recentRepoPaths { + go func(path string) { + defer wg.Done() + currentBranches.Store(path, gui.getCurrentBranch(path)) + }(path) + } + + wg.Wait() + menuItems := slices.Map(recentRepoPaths, func(path string) *types.MenuItem { branchName, _ := currentBranches.Load(path) if icons.IsIconEnabled() { - branchName = icons.BRANCH_ICON + " " + branchName + branchName = icons.BRANCH_ICON + " " + fmt.Sprintf("%v", branchName) } return &types.MenuItem{