diff options
author | Bjørn Erik Pedersen <[email protected]> | 2023-01-24 20:57:15 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2023-01-25 17:35:23 +0100 |
commit | 4ef9baf5bd24b6a105f78eba1147dad9ffabd82a (patch) | |
tree | 70b6de66d2baf3ccda53a05d488ac05964534760 /helpers | |
parent | 93ed6e447a24f8d08f136bd35fe3117bd6b29396 (diff) | |
download | hugo-4ef9baf5bd24b6a105f78eba1147dad9ffabd82a.tar.gz hugo-4ef9baf5bd24b6a105f78eba1147dad9ffabd82a.zip |
Only invoke a given cached partial once
Note that this is backed by a LRU cache (which we soon shall see more usage of), so if you're a heavy user of cached partials it may be evicted and
refreshed if needed. But in most cases every partial is only invoked once.
This commit also adds a timeout (the global `timeout` config option) to make infinite recursion in partials
easier to reason about.
```
name old time/op new time/op delta
IncludeCached-10 8.92ms ± 0% 8.48ms ± 1% -4.87% (p=0.016 n=4+5)
name old alloc/op new alloc/op delta
IncludeCached-10 6.65MB ± 0% 5.17MB ± 0% -22.32% (p=0.002 n=6+6)
name old allocs/op new allocs/op delta
IncludeCached-10 117k ± 0% 71k ± 0% -39.44% (p=0.002 n=6+6)
```
Closes #4086
Updates #9588
Diffstat (limited to 'helpers')
-rw-r--r-- | helpers/general.go | 22 | ||||
-rw-r--r-- | helpers/general_test.go | 7 |
2 files changed, 1 insertions, 28 deletions
diff --git a/helpers/general.go b/helpers/general.go index 462ec773d..c8a676829 100644 --- a/helpers/general.go +++ b/helpers/general.go @@ -23,7 +23,6 @@ import ( "os" "path/filepath" "sort" - "strconv" "strings" "sync" "unicode" @@ -31,8 +30,6 @@ import ( "github.com/gohugoio/hugo/common/loggers" - "github.com/mitchellh/hashstructure" - "github.com/gohugoio/hugo/common/hugo" "github.com/spf13/afero" @@ -219,7 +216,7 @@ func ReaderContains(r io.Reader, subslice []byte) bool { // GetTitleFunc returns a func that can be used to transform a string to // title case. // -// The supported styles are +// # The supported styles are // // - "Go" (strings.Title) // - "AP" (see https://www.apstylebook.com/) @@ -523,20 +520,3 @@ func PrintFs(fs afero.Fs, path string, w io.Writer) { return nil }) } - -// HashString returns a hash from the given elements. -// It will panic if the hash cannot be calculated. -func HashString(elements ...any) string { - var o any - if len(elements) == 1 { - o = elements[0] - } else { - o = elements - } - - hash, err := hashstructure.Hash(o, nil) - if err != nil { - panic(err) - } - return strconv.FormatUint(hash, 10) -} diff --git a/helpers/general_test.go b/helpers/general_test.go index 75119f01d..95d9c5461 100644 --- a/helpers/general_test.go +++ b/helpers/general_test.go @@ -458,10 +458,3 @@ func BenchmarkUniqueStrings(b *testing.B) { } }) } - -func TestHashString(t *testing.T) { - c := qt.New(t) - - c.Assert(HashString("a", "b"), qt.Equals, "2712570657419664240") - c.Assert(HashString("ab"), qt.Equals, "590647783936702392") -} |