Skip to content

Commit

Permalink
interp: Limit how often decode progress fn is called
Browse files Browse the repository at this point in the history
  • Loading branch information
wader committed Nov 29, 2021
1 parent 2f9d93d commit 8e5442f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/interp/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"math/big"
"strings"
"time"

"github.com/mitchellh/mapstructure"
"github.com/wader/fq/internal/gojqextra"
Expand Down Expand Up @@ -88,7 +89,14 @@ func (i *Interp) _decode(c interface{}, a []interface{}) interface{} {
ioextra.DiscardCtxWriter{Ctx: i.evalContext.ctx},
)
}
lastProgress := time.Now()
bbf.progressFn = func(approxReadBytes, totalSize int64) {
// make sure to not call too often as it's quite expensive
n := time.Now()
if n.Sub(lastProgress) < 200*time.Millisecond {
return
}
lastProgress = n
evalProgress(
map[string]interface{}{
"approx_read_bytes": approxReadBytes,
Expand Down

0 comments on commit 8e5442f

Please sign in to comment.