feat: short-circuit report fetching if only retrieving a single value

This speeds up report output when specifying a flag as extra data that isn't used will not be fetched unnecessarily.
This commit is contained in:
Jose Diaz-Gonzalez
2020-12-30 00:37:43 -05:00
parent 38b96c1e27
commit 0e320d2832
6 changed files with 10 additions and 6 deletions

View File

@@ -20,7 +20,7 @@ func ReportSingleApp(appName, infoFlag string) error {
trimPrefix := false
uppercaseFirstCharacter := true
infoFlags := common.CollectReport(appName, flags)
infoFlags := common.CollectReport(appName, infoFlag, flags)
return common.ReportSingleApp("app", appName, infoFlag, infoFlags, trimPrefix, uppercaseFirstCharacter)
}

View File

@@ -18,7 +18,7 @@ func ReportSingleApp(appName, infoFlag string) error {
trimPrefix := false
uppercaseFirstCharacter := true
infoFlags := common.CollectReport(appName, flags)
infoFlags := common.CollectReport(appName, infoFlag, flags)
return common.ReportSingleApp("buildpacks", appName, infoFlag, infoFlags, trimPrefix, uppercaseFirstCharacter)
}

View File

@@ -139,10 +139,14 @@ type ReportFunc func(string) string
// CollectReport iterates over a set of report functions
// to collect the :report output in parallel
func CollectReport(appName string, flags map[string]ReportFunc) map[string]string {
func CollectReport(appName string, infoFlag string, flags map[string]ReportFunc) map[string]string {
var sm sync.Map
var wg sync.WaitGroup
for flag, fn := range flags {
if infoFlag != "" && infoFlag != flag {
continue
}
wg.Add(1)
go func(flag string, fn ReportFunc) {
defer wg.Done()

View File

@@ -21,7 +21,7 @@ func ReportSingleApp(appName, infoFlag string) error {
trimPrefix := false
uppercaseFirstCharacter := true
infoFlags := common.CollectReport(appName, flags)
infoFlags := common.CollectReport(appName, infoFlag, flags)
return common.ReportSingleApp("network", appName, infoFlag, infoFlags, trimPrefix, uppercaseFirstCharacter)
}

View File

@@ -20,7 +20,7 @@ func ReportSingleApp(appName string, infoFlag string) error {
trimPrefix := false
uppercaseFirstCharacter := true
infoFlags := common.CollectReport(appName, flags)
infoFlags := common.CollectReport(appName, infoFlag, flags)
return common.ReportSingleApp("proxy", appName, infoFlag, infoFlags, trimPrefix, uppercaseFirstCharacter)
}

View File

@@ -46,7 +46,7 @@ func ReportSingleApp(appName, infoFlag string) error {
trimPrefix := false
uppercaseFirstCharacter := true
infoFlags := common.CollectReport(appName, flags)
infoFlags := common.CollectReport(appName, infoFlag, flags)
return common.ReportSingleApp("ps", appName, infoFlag, infoFlags, trimPrefix, uppercaseFirstCharacter)
}