From 0e320d28322308e100a53c5bedeb8a45ce3f73d8 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Wed, 30 Dec 2020 00:37:43 -0500 Subject: [PATCH] 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. --- plugins/apps/report.go | 2 +- plugins/buildpacks/report.go | 2 +- plugins/common/parallel.go | 6 +++++- plugins/network/report.go | 2 +- plugins/proxy/report.go | 2 +- plugins/ps/report.go | 2 +- 6 files changed, 10 insertions(+), 6 deletions(-) diff --git a/plugins/apps/report.go b/plugins/apps/report.go index ae0a9ba6c..d74d9ce51 100644 --- a/plugins/apps/report.go +++ b/plugins/apps/report.go @@ -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) } diff --git a/plugins/buildpacks/report.go b/plugins/buildpacks/report.go index b1e593a2b..b255095f2 100644 --- a/plugins/buildpacks/report.go +++ b/plugins/buildpacks/report.go @@ -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) } diff --git a/plugins/common/parallel.go b/plugins/common/parallel.go index b5bdb0f15..777ad1778 100644 --- a/plugins/common/parallel.go +++ b/plugins/common/parallel.go @@ -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() diff --git a/plugins/network/report.go b/plugins/network/report.go index a3bccdb02..ff9fcfdda 100644 --- a/plugins/network/report.go +++ b/plugins/network/report.go @@ -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) } diff --git a/plugins/proxy/report.go b/plugins/proxy/report.go index 0791eb273..f32365ab1 100644 --- a/plugins/proxy/report.go +++ b/plugins/proxy/report.go @@ -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) } diff --git a/plugins/ps/report.go b/plugins/ps/report.go index 42905bfd9..c24284ad8 100644 --- a/plugins/ps/report.go +++ b/plugins/ps/report.go @@ -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) }