From 44461e21df76694226b62b1d1f1caba207ca7d9e Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 29 Dec 2020 23:55:13 -0500 Subject: [PATCH] refactor: parallelize scheduler retrieval In many cases, a user may only set a global scheduler, and as such we waste the initial call to get the app scheduler. Parallelizing the fetch increases the speed at which we can check for the scheduler. --- plugins/common/common.go | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/plugins/common/common.go b/plugins/common/common.go index 05fbc8434..6d9c5ae5a 100644 --- a/plugins/common/common.go +++ b/plugins/common/common.go @@ -11,6 +11,7 @@ import ( "sort" "strconv" "strings" + "sync" "unicode" "github.com/ryanuber/columnize" @@ -64,17 +65,34 @@ func CommandUsage(helpHeader string, helpContent string) { // GetAppScheduler fetches the scheduler for a given application func GetAppScheduler(appName string) string { - if appName == "--global" { - appName = "" - } + appScheduler := "" + globalScheduler := "" - b, _ := PlugnTriggerOutput("config-get", []string{appName, "DOKKU_SCHEDULER"}...) - value := strings.TrimSpace(string(b[:])) - if value != "" { - return value - } + var wg sync.WaitGroup - return GetGlobalScheduler() + if appName != "--global" { + wg.Add(1) + go func() { + defer wg.Done() + b, _ := PlugnTriggerOutput("config-get", []string{appName, "DOKKU_SCHEDULER"}...) + value := strings.TrimSpace(string(b[:])) + if value != "" { + appScheduler = value + } + }() + } + wg.Add(1) + go func() { + defer wg.Done() + globalScheduler = GetGlobalScheduler() + }() + + wg.Wait() + + if appScheduler == "" { + appScheduler = globalScheduler + } + return appScheduler } // GetGlobalScheduler fetchs the global scheduler