1
0
mirror of https://github.com/go-task/task.git synced 2025-02-03 13:22:11 +02:00

cache dymanic variables

This commit is contained in:
Andrey Nering 2017-07-05 21:03:59 -03:00
parent 222b5cb587
commit ad1a440576
2 changed files with 15 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import (
"os"
"path/filepath"
"strings"
"sync"
"github.com/go-task/task/execext"
@ -33,6 +34,9 @@ type Executor struct {
taskvars Vars
watchingFiles map[string]struct{}
dynamicCache Vars
muDynamicCache sync.Mutex
}
// Vars is a string[string] variables map
@ -71,6 +75,10 @@ func (e *Executor) Run(args ...string) error {
e.Stderr = os.Stderr
}
if e.dynamicCache == nil {
e.dynamicCache = make(Vars, 10)
}
// check if given tasks exist
for _, a := range args {
if _, ok := e.Tasks[a]; !ok {

View File

@ -26,6 +26,12 @@ func (e *Executor) handleDynamicVariableContent(value string) (string, error) {
return value, nil
}
e.muDynamicCache.Lock()
defer e.muDynamicCache.Unlock()
if result, ok := e.dynamicCache[value]; ok {
return result, nil
}
buff := bytes.NewBuffer(nil)
opts := &execext.RunCommandOptions{
@ -46,6 +52,7 @@ func (e *Executor) handleDynamicVariableContent(value string) (string, error) {
result = strings.TrimSpace(result)
e.verbosePrintfln(`task: dynamic variable: "%s", result: "%s"`, value, result)
e.dynamicCache[value] = result
return result, nil
}