diff --git a/external/aliases/aliases.go b/external/aliases/aliases.go index 3011392..67d43db 100644 --- a/external/aliases/aliases.go +++ b/external/aliases/aliases.go @@ -15,6 +15,7 @@ import ( "strconv" "strings" "sync" + "time" ) var mutex = &sync.RWMutex{} @@ -72,6 +73,20 @@ func getAliasesForSingleJsonApiType(jsonApiType string) map[string]*id.IdableAtt mutex.RUnlock() mutex.Lock() defer mutex.Unlock() + + done := make(chan bool, 1) + + defer close(done) + + go func() { + select { + case <-done: + break + case <-time.After(2 * time.Second): + log.Warnf("Loading of aliases for %s has taken more than 2 seconds, if you don't need aliases consider the --skip-alias-processing argument. You can also clear aliases by using `epcc aliases clear `", jsonApiType) + } + }() + aliasFile := getAliasFileForJsonApiType(getAliasDataDirectory(), jsonApiType) aliasMap = map[string]*id.IdableAttributes{} @@ -105,6 +120,8 @@ func getAliasesForSingleJsonApiType(jsonApiType string) map[string]*id.IdableAtt log.Tracef("Aliases for type [%s] loaded, with %d aliases", jsonApiType, len(aliasMap)) } + done <- true + } else { mutex.RUnlock() } @@ -533,6 +550,18 @@ func FlushAliases() int { } func SyncAliases() int { + done := make(chan bool, 1) + + defer close(done) + + go func() { + select { + case <-done: + break + case <-time.After(1 * time.Second): + log.Warnf("Saving of aliases took longer than 1 seconds, if you don't need aliases consider the --skip-alias-processing argument. You can also clear aliases by using `epcc aliases clear ") + } + }() syncedFiles := 0 mutex.RLock() @@ -553,6 +582,9 @@ func SyncAliases() int { // https://github.com/golang/go/issues/20599 tmpFileName := aliasFile + "." + uuid.New().String() + if len(aliasesForType) > 10000 { + log.Warnf("There are more than 10,000 aliases for type %s, you may notice a slow down when using epcc. If you don't need aliases consider the --skip-alias-processing argument. You can also clear aliases by using `epcc aliases clear ", jsonApiType) + } marshal, err := yaml.Marshal(aliasesForType) if err != nil { @@ -579,6 +611,7 @@ func SyncAliases() int { log.Debugf("Syncing aliases to disk, %d files changed", syncedFiles) + done <- true return syncedFiles } diff --git a/external/json/print_json.go b/external/json/print_json.go index 91e39c8..0b5a8f8 100644 --- a/external/json/print_json.go +++ b/external/json/print_json.go @@ -51,6 +51,8 @@ func printJsonToWriter(json string, w io.Writer) error { done := make(chan bool, 1) + defer close(done) + if !MonochromeOutput { go func() { select {