Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ require (
github.com/gohugoio/go-radix v1.2.0
github.com/gohugoio/hashstructure v0.6.0
github.com/gohugoio/httpcache v0.8.0
github.com/gohugoio/hugo-goldmark-extensions/extras v0.5.0
github.com/gohugoio/hugo-goldmark-extensions/passthrough v0.3.1
github.com/gohugoio/hugo-goldmark-extensions/extras v0.6.0
github.com/gohugoio/hugo-goldmark-extensions/passthrough v0.4.0
github.com/gohugoio/locales v0.14.0
github.com/gohugoio/localescompressed v1.0.1
github.com/google/go-cmp v0.7.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,10 @@ github.com/gohugoio/hashstructure v0.6.0 h1:7wMB/2CfXoThFYhdWRGv3u3rUM761Cq29CxU
github.com/gohugoio/hashstructure v0.6.0/go.mod h1:lapVLk9XidheHG1IQ4ZSbyYrXcaILU1ZEP/+vno5rBQ=
github.com/gohugoio/httpcache v0.8.0 h1:hNdsmGSELztetYCsPVgjA960zSa4dfEqqF/SficorCU=
github.com/gohugoio/httpcache v0.8.0/go.mod h1:fMlPrdY/vVJhAriLZnrF5QpN3BNAcoBClgAyQd+lGFI=
github.com/gohugoio/hugo-goldmark-extensions/extras v0.5.0 h1:dco+7YiOryRoPOMXwwaf+kktZSCtlFtreNdiJbETvYE=
github.com/gohugoio/hugo-goldmark-extensions/extras v0.5.0/go.mod h1:CRrxQTKeM3imw+UoS4EHKyrqB7Zp6sAJiqHit+aMGTE=
github.com/gohugoio/hugo-goldmark-extensions/passthrough v0.3.1 h1:nUzXfRTszLliZuN0JTKeunXTRaiFX6ksaWP0puLLYAY=
github.com/gohugoio/hugo-goldmark-extensions/passthrough v0.3.1/go.mod h1:Wy8ThAA8p2/w1DY05vEzq6EIeI2mzDjvHsu7ULBVwog=
github.com/gohugoio/hugo-goldmark-extensions/extras v0.6.0 h1:c16engMi6zyOGeCrP73RWC9fom94wXGpVzncu3GXBjI=
github.com/gohugoio/hugo-goldmark-extensions/extras v0.6.0/go.mod h1:e3+TRCT4Uz6NkZOAVMOMgPeJ+7KEtQMX8hdB+WG4qRs=
github.com/gohugoio/hugo-goldmark-extensions/passthrough v0.4.0 h1:awFlqaCQ0N/RS9ndIBpDYNms101I1sGbDRG1bksa5Js=
github.com/gohugoio/hugo-goldmark-extensions/passthrough v0.4.0/go.mod h1:lK1CjqrueCd3OBnsLLQJGrQ+uodWfT9M9Cq2zfDWJCE=
github.com/gohugoio/locales v0.14.0 h1:Q0gpsZwfv7ATHMbcTNepFd59H7GoykzWJIxi113XGDc=
github.com/gohugoio/locales v0.14.0/go.mod h1:ip8cCAv/cnmVLzzXtiTpPwgJ4xhKZranqNqtoIu0b/4=
github.com/gohugoio/localescompressed v1.0.1 h1:KTYMi8fCWYLswFyJAeOtuk/EkXR/KPTHHNN9OS+RTxo=
Expand Down
59 changes: 59 additions & 0 deletions tpl/collections/collections_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@
package collections_test

import (
"context"
"fmt"
"testing"

"github.com/gohugoio/hugo/hugolib"
"github.com/gohugoio/hugo/resources/page"
"github.com/gohugoio/hugo/tpl/collections"
)

// Issue 9585
Expand Down Expand Up @@ -555,3 +559,58 @@ tags_weight: 20
"intersect:[]string:[a b c d]",
)
}

func BenchmarkWhereAndSortPages(b *testing.B) {
pageTemplate := `
-- content/page%04d.md --
---
title: Page%04d
---
`

files := `
-- hugo.toml --
-- layouts/all.html --
All.
`

for i := 0; i < 500; i++ {
files += fmt.Sprintf(pageTemplate, i, i)
}

bb := hugolib.Test(b, files, hugolib.TestOptWithConfig(func(conf *hugolib.IntegrationTestConfig) {
conf.BuildCfg = hugolib.BuildCfg{
SkipRender: true,
}
}))

s := bb.H.Sites[0]
seq := s.RegularPages()
ns := s.TemplateStore.GetTemplateFuncsNamespace("collections").(*collections.Namespace)

b.Run("Where", func(b *testing.B) {
for b.Loop() {
v, err := ns.Where(context.Background(), seq, "Title", "ge", "Page0480")
if err != nil {
b.Fatal(err)
}
res := v.(page.Pages)
if len(res) != 20 {
b.Fatalf("Where didn't return an expected result, got %d", len(res))
}
}
})

b.Run("Sort", func(b *testing.B) {
for b.Loop() {
v, err := ns.Sort(context.Background(), s.RegularPages(), "Title", "desc")
if err != nil {
b.Fatal(err)
}
res := v.(page.Pages)
if len(res) != 500 {
b.Fatalf("Sort didn't return an expected result, got %d", len(res))
}
}
})
}
38 changes: 31 additions & 7 deletions tpl/collections/where_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -906,18 +906,42 @@ func BenchmarkWhereOps(b *testing.B) {

func BenchmarkWhereMap(b *testing.B) {
ns := newNs()
seq := map[string]string{}
seqString := map[string]string{}
seqAny := map[string]any{}
seqInt := map[string]int{}

for i := range 1000 {
seq[fmt.Sprintf("key%d", i)] = "value"
seqString[fmt.Sprintf("key%d", i)] = "value"
seqAny[fmt.Sprintf("key%d", i)] = "value"
seqInt[fmt.Sprintf("key%d", i)] = i
}

for b.Loop() {
_, err := ns.Where(context.Background(), seq, "key", "eq", "value")
if err != nil {
b.Fatal(err)
b.Run("String", func(b *testing.B) {
for b.Loop() {
_, err := ns.Where(context.Background(), seqString, "key", "eq", "value")
if err != nil {
b.Fatal(err)
}
}
}
})

b.Run("Int", func(b *testing.B) {
for b.Loop() {
_, err := ns.Where(context.Background(), seqAny, "key", "eq", 42)
if err != nil {
b.Fatal(err)
}
}
})

b.Run("Any", func(b *testing.B) {
for b.Loop() {
_, err := ns.Where(context.Background(), seqAny, "key", "eq", "value")
if err != nil {
b.Fatal(err)
}
}
})
}

func BenchmarkWhereSliceOfStructPointersWithMethod(b *testing.B) {
Expand Down
10 changes: 10 additions & 0 deletions tpl/tplimpl/templatestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,16 @@ func (s TemplateStore) WithSiteOpts(opts SiteOptions) *TemplateStore {
return &s
}

// GetTemplateFuncsNamespace returns the given template funcs namespace.
// Used in tests only.
func (s *TemplateStore) GetTemplateFuncsNamespace(ns string) any {
v, err := s.storeSite.opts.TemplateFuncs[ns].(func(cctx context.Context, args ...any) (any, error))(context.Background())
if err != nil {
panic(fmt.Sprintf("template func namespace %q not found: %s", ns, err))
}
return v
}

func (s *TemplateStore) findBestMatchGet(key string, category Category,
consider func(candidate *TemplInfo) bool, d1 TemplateDescriptor, dims1 sitesmatrix.VectorProvider, best *bestMatch,
) {
Expand Down
Loading