1
1
mirror of https://github.com/wader/fq.git synced 2024-11-27 14:14:58 +03:00

interp: Limit how often decode progress fn is called

This commit is contained in:
Mattias Wadman 2021-11-29 14:26:11 +01:00
parent 2f9d93d0ce
commit 8e5442f023

View File

@ -7,6 +7,7 @@ import (
"io"
"math/big"
"strings"
"time"
"github.com/mitchellh/mapstructure"
"github.com/wader/fq/internal/gojqextra"
@ -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,