modules: Adjust the log throttle logic a little

This commit is contained in:
Bjørn Erik Pedersen 2023-10-28 17:40:07 +02:00
parent 66904097e0
commit 3f64b5a3de
No known key found for this signature in database

View file

@ -106,16 +106,18 @@ func NewClient(cfg ClientConfig) *Client {
var throttleSince time.Time var throttleSince time.Time
throttle := func(f func()) { throttle := func(f func()) {
// Skip the first call.
// This is used for "download" etc. and we want to avoid
// logging anything if it is fast.
if throttleSince.IsZero() { if throttleSince.IsZero() {
throttleSince = time.Now() throttleSince = time.Now()
f()
return return
} }
if time.Since(throttleSince) < 6*time.Second { if time.Since(throttleSince) < 6*time.Second {
return return
} }
throttleSince = time.Now()
f() f()
throttleSince = time.Now()
} }
return &Client{ return &Client{