summaryrefslogtreecommitdiffstats
path: root/hugolib/pageCache_test.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-03-15 09:37:30 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-03-16 10:10:01 +0100
commitffaec4ca8c4c6fd05b195879ccd65acf2fd5a6ac (patch)
tree28d4a68d5b41d5ccd769208856d0e3b4f086ebe5 /hugolib/pageCache_test.go
parent91fb8f1b59cce50de914d66dac1d406655c3c43b (diff)
downloadhugo-ffaec4ca8c4c6fd05b195879ccd65acf2fd5a6ac.tar.gz
hugo-ffaec4ca8c4c6fd05b195879ccd65acf2fd5a6ac.zip
Add a way to merge pages by language
As an example: ```html {{ $pages := .Site.RegularPages | lang.Merge $frSite.RegularPages | lang.Merge $enSite.RegularPages }} ``` Will "fill in the gaps" in the current site with, from left to right, content from the French site, and lastly the English. Fixes #4463
Diffstat (limited to 'hugolib/pageCache_test.go')
-rw-r--r--hugolib/pageCache_test.go21
1 files changed, 18 insertions, 3 deletions
diff --git a/hugolib/pageCache_test.go b/hugolib/pageCache_test.go
index aa2adf6e8..52a7f4494 100644
--- a/hugolib/pageCache_test.go
+++ b/hugolib/pageCache_test.go
@@ -14,6 +14,7 @@
package hugolib
import (
+ "strconv"
"sync"
"sync/atomic"
"testing"
@@ -51,17 +52,17 @@ func TestPageCache(t *testing.T) {
defer wg.Done()
for k, pages := range testPageSets {
l1.Lock()
- p, c := c1.get("k1", pages, nil)
+ p, c := c1.get("k1", nil, pages)
assert.Equal(t, !atomic.CompareAndSwapUint64(&o1, uint64(k), uint64(k+1)), c)
l1.Unlock()
- p2, c2 := c1.get("k1", p, nil)
+ p2, c2 := c1.get("k1", nil, p)
assert.True(t, c2)
assert.True(t, fastEqualPages(p, p2))
assert.True(t, fastEqualPages(p, pages))
assert.NotNil(t, p)
l2.Lock()
- p3, c3 := c1.get("k2", pages, changeFirst)
+ p3, c3 := c1.get("k2", changeFirst, pages)
assert.Equal(t, !atomic.CompareAndSwapUint64(&o2, uint64(k), uint64(k+1)), c3)
l2.Unlock()
assert.NotNil(t, p3)
@@ -71,3 +72,17 @@ func TestPageCache(t *testing.T) {
}
wg.Wait()
}
+
+func BenchmarkPageCache(b *testing.B) {
+ cache := newPageCache()
+ pages := make(Pages, 30)
+ for i := 0; i < 30; i++ {
+ pages[i] = &Page{title: "p" + strconv.Itoa(i)}
+ }
+ key := "key"
+
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ cache.getP(key, nil, pages)
+ }
+}