]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
modules: Adjust the log throttle logic a little
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sat, 28 Oct 2023 15:40:07 +0000 (17:40 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sat, 28 Oct 2023 15:40:07 +0000 (17:40 +0200)
modules/client.go

index b3dad498b97c1f4abeb4d09a4314f12d42c7e417..9a04156320009665b5b8f1b368bb6b5c02624f20 100644 (file)
@@ -106,16 +106,18 @@ func NewClient(cfg ClientConfig) *Client {
 
        var throttleSince time.Time
        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() {
                        throttleSince = time.Now()
-                       f()
                        return
                }
                if time.Since(throttleSince) < 6*time.Second {
                        return
                }
-               throttleSince = time.Now()
                f()
+               throttleSince = time.Now()
        }
 
        return &Client{