Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolves #380 - Warn if alias loading or saving is slow #381

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions external/aliases/aliases.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"strconv"
"strings"
"sync"
"time"
)

var mutex = &sync.RWMutex{}
Expand Down Expand Up @@ -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 <TYPE>`", jsonApiType)
}
}()

aliasFile := getAliasFileForJsonApiType(getAliasDataDirectory(), jsonApiType)

aliasMap = map[string]*id.IdableAttributes{}
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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 <TYPE>")
}
}()

syncedFiles := 0
mutex.RLock()
Expand All @@ -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 <TYPE> ", jsonApiType)
}
marshal, err := yaml.Marshal(aliasesForType)

if err != nil {
Expand All @@ -579,6 +611,7 @@ func SyncAliases() int {

log.Debugf("Syncing aliases to disk, %d files changed", syncedFiles)

done <- true
return syncedFiles

}
2 changes: 2 additions & 0 deletions external/json/print_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down