mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-28 06:30:33 +03: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:
parent
dffd7da07c
commit
a10b2cd372
26 changed files with 348 additions and 90 deletions
|
@ -23,6 +23,19 @@ import (
|
|||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
// These are the settings that should only be looked up in the global Viper
|
||||
// config and not per language.
|
||||
// This list may not be complete, but contains only settings that we know
|
||||
// will be looked up in both.
|
||||
// This isn't perfect, but it is ultimately the user who shoots him/herself in
|
||||
// the foot.
|
||||
// See the pathSpec.
|
||||
var globalOnlySettings = map[string]bool{
|
||||
strings.ToLower("defaultContentLanguageInSubdir"): true,
|
||||
strings.ToLower("defaultContentLanguage"): true,
|
||||
strings.ToLower("multilingual"): true,
|
||||
}
|
||||
|
||||
type Language struct {
|
||||
Lang string
|
||||
LanguageName string
|
||||
|
@ -81,7 +94,7 @@ func (l *Language) Params() map[string]interface{} {
|
|||
}
|
||||
|
||||
func (l *Language) SetParam(k string, v interface{}) {
|
||||
l.params[k] = v
|
||||
l.params[strings.ToLower(k)] = v
|
||||
}
|
||||
|
||||
func (l *Language) GetBool(key string) bool { return cast.ToBool(l.Get(key)) }
|
||||
|
@ -101,8 +114,10 @@ func (l *Language) Get(key string) interface{} {
|
|||
panic("language not set")
|
||||
}
|
||||
key = strings.ToLower(key)
|
||||
if v, ok := l.params[key]; ok {
|
||||
return v
|
||||
if !globalOnlySettings[key] {
|
||||
if v, ok := l.params[key]; ok {
|
||||
return v
|
||||
}
|
||||
}
|
||||
return viper.Get(key)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue