1
0
mirror of https://github.com/gohugoio/hugo.git synced 2024-05-11 05:54:58 +00:00

Avoid reading from Viper for path and URL funcs

The gain, given the "real sites benchmark" below, is obvious:

```
benchmark           old ns/op       new ns/op       delta
BenchmarkHugo-4     14497594101     13084156335     -9.75%

benchmark           old allocs     new allocs     delta
BenchmarkHugo-4     57404335       48282002       -15.89%

benchmark           old bytes       new bytes      delta
BenchmarkHugo-4     9933505624      9721984424     -2.13%
```

Fixes #2495
This commit is contained in:
Bjørn Erik Pedersen
2016-10-24 13:45:30 +02:00
committed by GitHub
parent dffd7da07c
commit a10b2cd372
26 changed files with 348 additions and 90 deletions

View File

@@ -508,16 +508,16 @@ func newPaginator(elements []paginatedElement, total, size int, urlFactory pagin
}
func newPaginationURLFactory(pathElements ...string) paginationURLFactory {
paginatePath := helpers.Config().GetString("paginatePath")
pathSpec := helpers.CurrentPathSpec()
return func(page int) string {
var rel string
if page == 1 {
rel = fmt.Sprintf("/%s/", path.Join(pathElements...))
} else {
rel = fmt.Sprintf("/%s/%s/%d/", path.Join(pathElements...), paginatePath, page)
rel = fmt.Sprintf("/%s/%s/%d/", path.Join(pathElements...), pathSpec.PaginatePath(), page)
}
return helpers.URLizeAndPrep(rel)
return pathSpec.URLizeAndPrep(rel)
}
}