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

@@ -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()