mirror of
https://github.com/gohugoio/hugo.git
synced 2024-05-11 05:54:58 +00:00
Lazy calculate WordCount, ReadingTime and FuzzyWordCount
This avoids having to execute these expensive operations for sites not using these values. This commit sums up a set of wordcounting and autosummary related performance improvements. The effect of these kind of depends on what features your site use, but a benchmark from 4 Hugo sites in the wild shows promise: ``` benchmark old ns/op new ns/op delta BenchmarkHugo-4 21293005843 20032857342 -5.92% benchmark old allocs new allocs delta BenchmarkHugo-4 65290922 65186032 -0.16% benchmark old bytes new bytes delta BenchmarkHugo-4 9771213416 9681866464 -0.91% ``` Closes #2378
This commit is contained in:
@@ -55,7 +55,7 @@ func TestSplitPageGroups(t *testing.T) {
|
||||
// first group 10 in weight
|
||||
assert.Equal(t, 10, pg.Key)
|
||||
for _, p := range pg.Pages {
|
||||
assert.True(t, p.FuzzyWordCount%2 == 0) // magic test
|
||||
assert.True(t, p.fuzzyWordCount%2 == 0) // magic test
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -70,7 +70,7 @@ func TestSplitPageGroups(t *testing.T) {
|
||||
// last should have 5 in weight
|
||||
assert.Equal(t, 5, pg.Key)
|
||||
for _, p := range pg.Pages {
|
||||
assert.True(t, p.FuzzyWordCount%2 != 0) // magic test
|
||||
assert.True(t, p.fuzzyWordCount%2 != 0) // magic test
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -443,10 +443,10 @@ func TestPage(t *testing.T) {
|
||||
page21, _ := f2.page(1)
|
||||
page2Nil, _ := f2.page(3)
|
||||
|
||||
assert.Equal(t, 1, page11.FuzzyWordCount)
|
||||
assert.Equal(t, 3, page11.fuzzyWordCount)
|
||||
assert.Nil(t, page1Nil)
|
||||
|
||||
assert.Equal(t, 1, page21.FuzzyWordCount)
|
||||
assert.Equal(t, 3, page21.fuzzyWordCount)
|
||||
assert.Nil(t, page2Nil)
|
||||
}
|
||||
|
||||
@@ -468,7 +468,7 @@ func createTestPages(num int) Pages {
|
||||
if i%2 == 0 {
|
||||
w = 10
|
||||
}
|
||||
pages[i].FuzzyWordCount = i
|
||||
pages[i].fuzzyWordCount = i + 2
|
||||
pages[i].Weight = w
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user