]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Revise the use of htime.Since/htime.Now
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 9 May 2022 08:05:19 +0000 (10:05 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 9 May 2022 12:18:40 +0000 (14:18 +0200)
We cannot (also, it doesn't add any value)  use that when the `clock` is set,

* To measure time (before that global is set)
* To compare file timestamps re cache eviction

Fixes #9868

cache/filecache/filecache.go
commands/commands.go
commands/hugo.go
commands/server.go
common/loggers/loggers.go
metrics/metrics.go
modules/collect.go
tpl/partials/partials.go
tpl/tplimpl/template.go

index 3104d8ac6dae1f3dcda6277b6af572a173bc350d..63d939ef6902b3216a7f83d95045e1aa07ed1583 100644 (file)
@@ -24,7 +24,6 @@ import (
        "sync"
        "time"
 
-       "github.com/gohugoio/hugo/common/htime"
        "github.com/gohugoio/hugo/common/hugio"
 
        "github.com/gohugoio/hugo/helpers"
@@ -296,7 +295,10 @@ func (c *Cache) isExpired(modTime time.Time) bool {
        if c.maxAge < 0 {
                return false
        }
-       return c.maxAge == 0 || htime.Since(modTime) > c.maxAge
+
+       // Note the use of time.Since here.
+       // We cannot use Hugo's global Clock for this.
+       return c.maxAge == 0 || time.Since(modTime) > c.maxAge
 }
 
 // For testing
index d55a4e9aab30a4a8209426a8f2262c7ee55cc273..aee6a72841aa90b5574995425e6d9829d1c0d9aa 100644 (file)
@@ -18,7 +18,6 @@ import (
        "os"
        "time"
 
-       "github.com/gohugoio/hugo/common/htime"
        "github.com/gohugoio/hugo/common/hugo"
        "github.com/gohugoio/hugo/common/loggers"
        hpaths "github.com/gohugoio/hugo/common/paths"
@@ -152,7 +151,7 @@ built with love by spf13 and friends in Go.
 
 Complete documentation is available at https://gohugo.io/.`,
                RunE: func(cmd *cobra.Command, args []string) error {
-                       defer cc.timeTrack(htime.Now(), "Total")
+                       defer cc.timeTrack(time.Now(), "Total")
                        cfgInit := func(c *commandeer) error {
                                if cc.buildWatch {
                                        c.Set("disableLiveReload", true)
@@ -238,7 +237,7 @@ func (cc *hugoBuilderCommon) timeTrack(start time.Time, name string) {
        if cc.quiet {
                return
        }
-       elapsed := htime.Since(start)
+       elapsed := time.Since(start)
        fmt.Printf("%s in %v ms\n", name, int(1000*elapsed.Seconds()))
 }
 
index 43ec7e5c70875b64b60cc4d9a2f1bd256536134a..c13fdce06048bae00869733f904c85c5be7a3acb 100644 (file)
@@ -681,7 +681,11 @@ func (c *commandeer) firstPathSpec() *helpers.PathSpec {
 }
 
 func (c *commandeer) timeTrack(start time.Time, name string) {
-       elapsed := htime.Since(start)
+       // Note the use of time.Since here and time.Now in the callers.
+       // We have a htime.Sinnce, but that may be adjusted to the future,
+       // and that does not make sense here, esp. when used before the
+       // global Clock is initialized.
+       elapsed := time.Since(start)
        c.logger.Printf("%s in %v ms", name, int(1000*elapsed.Seconds()))
 }
 
@@ -792,7 +796,7 @@ func (c *commandeer) fullRebuild(changeType string) {
                        time.Sleep(2 * time.Second)
                }()
 
-               defer c.timeTrack(htime.Now(), "Rebuilt")
+               defer c.timeTrack(time.Now(), "Rebuilt")
 
                c.commandeerHugoState = newCommandeerHugoState()
                err := c.loadConfig()
@@ -1137,7 +1141,7 @@ func (c *commandeer) handleEvents(watcher *watcher.Batcher,
                c.changeDetector.PrepareNew()
 
                func() {
-                       defer c.timeTrack(htime.Now(), "Total")
+                       defer c.timeTrack(time.Now(), "Total")
                        if err := c.rebuildSites(dynamicEvents); err != nil {
                                c.handleBuildErr(err, "Rebuild failed")
                        }
index 5fdde21c588219489b5fdd22ac9c119ab8374d2c..27b12cb32ed1052c926c8141c98f2029f54c531c 100644 (file)
@@ -251,7 +251,7 @@ func (sc *serverCmd) server(cmd *cobra.Command, args []string) error {
        }
 
        err = func() error {
-               defer c.timeTrack(htime.Now(), "Built")
+               defer c.timeTrack(time.Now(), "Built")
                err := c.serverBuild()
                if err != nil {
                        cmd.PrintErrln("Error:", err.Error())
index 6b73c9f32c1283d8080e0c1383c25c3f43842952..14c76ae4576d53039b4dc0fd77149601ef72865c 100644 (file)
@@ -24,7 +24,6 @@ import (
        "runtime"
        "time"
 
-       "github.com/gohugoio/hugo/common/htime"
        "github.com/gohugoio/hugo/common/terminal"
 
        jww "github.com/spf13/jwalterweatherman"
@@ -177,7 +176,7 @@ func (l *logger) Out() io.Writer {
 // PrintTimerIfDelayed prints a time statement to the FEEDBACK logger
 // if considerable time is spent.
 func (l *logger) PrintTimerIfDelayed(start time.Time, name string) {
-       elapsed := htime.Since(start)
+       elapsed := time.Since(start)
        milli := int(1000 * elapsed.Seconds())
        if milli < 500 {
                return
@@ -186,7 +185,7 @@ func (l *logger) PrintTimerIfDelayed(start time.Time, name string) {
 }
 
 func (l *logger) PrintTimer(start time.Time, name string) {
-       elapsed := htime.Since(start)
+       elapsed := time.Since(start)
        milli := int(1000 * elapsed.Seconds())
        l.Printf("%s in %v ms", name, milli)
 }
index 471f48a047150663c47b06172f42ab15d33dfce3..9c46fdf7ee31d068a9747f85a687cc46baf8c5cd 100644 (file)
@@ -25,7 +25,6 @@ import (
        "sync"
        "time"
 
-       "github.com/gohugoio/hugo/common/htime"
        "github.com/gohugoio/hugo/common/types"
        "github.com/gohugoio/hugo/compare"
        "github.com/gohugoio/hugo/helpers"
@@ -130,7 +129,7 @@ func (s *Store) TrackValue(key string, value any, cached bool) {
 // MeasureSince adds a measurement for key to the metric store.
 func (s *Store) MeasureSince(key string, start time.Time) {
        s.mu.Lock()
-       s.metrics[key] = append(s.metrics[key], htime.Since(start))
+       s.metrics[key] = append(s.metrics[key], time.Since(start))
        s.mu.Unlock()
 }
 
index 4f5b1c36faa18f9a2cda52ae2fb6f5777c9bf753..ff83f9ecca86f28f0dc8b445b2042bbf8aa0aed6 100644 (file)
@@ -23,7 +23,6 @@ import (
        "time"
 
        "github.com/bep/debounce"
-       "github.com/gohugoio/hugo/common/htime"
        "github.com/gohugoio/hugo/common/loggers"
 
        "github.com/spf13/cast"
@@ -506,7 +505,7 @@ func (c *collector) applyThemeConfig(tc *moduleAdapter) error {
 }
 
 func (c *collector) collect() {
-       defer c.logger.PrintTimerIfDelayed(htime.Now(), "hugo: collected modules")
+       defer c.logger.PrintTimerIfDelayed(time.Now(), "hugo: collected modules")
        d := debounce.New(2 * time.Second)
        d(func() {
                c.logger.Println("hugo: downloading modules …")
index 9ded32a7134e98a49e324c9ad887f74d4d3d1ede..eb4ebfe321a2301171bcac97ecde55660cf186da 100644 (file)
@@ -25,8 +25,8 @@ import (
        "reflect"
        "strings"
        "sync"
+       "time"
 
-       "github.com/gohugoio/hugo/common/htime"
        texttemplate "github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate"
 
        "github.com/gohugoio/hugo/helpers"
@@ -222,7 +222,7 @@ func createKey(name string, variants ...any) (partialCacheKey, error) {
 var errUnHashable = errors.New("unhashable")
 
 func (ns *Namespace) getOrCreate(ctx context.Context, key partialCacheKey, context any) (result any, err error) {
-       start := htime.Now()
+       start := time.Now()
        defer func() {
                if r := recover(); r != nil {
                        err = r.(error)
index d352f02e825d544eb9d50dc08cc626ee5173f548..c092ff638165ea2c766519c245d8701fc7b5a713 100644 (file)
@@ -27,10 +27,10 @@ import (
        "sort"
        "strings"
        "sync"
+       "time"
        "unicode"
        "unicode/utf8"
 
-       "github.com/gohugoio/hugo/common/htime"
        "github.com/gohugoio/hugo/common/types"
 
        "github.com/gohugoio/hugo/helpers"
@@ -235,7 +235,7 @@ func (t *templateExec) ExecuteWithContext(ctx context.Context, templ tpl.Templat
                defer rlocker.RUnlock()
        }
        if t.Metrics != nil {
-               defer t.Metrics.MeasureSince(templ.Name(), htime.Now())
+               defer t.Metrics.MeasureSince(templ.Name(), time.Now())
        }
 
        if t.templateUsageTracker != nil {