aboutsummaryrefslogtreecommitdiffhomepage
path: root/identity
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2020-09-07 15:07:10 +0200
committerBjørn Erik Pedersen <[email protected]>2020-09-07 21:06:44 +0200
commit4055c121847847d8bd6b95a928185daee065091b (patch)
tree6620f51e7e89aa7ff0a9a93361d640ee5b297fea /identity
parent3ba7c92530a80f2f04fe57705ab05c247a6e8437 (diff)
downloadhugo-4055c121847847d8bd6b95a928185daee065091b.tar.gz
hugo-4055c121847847d8bd6b95a928185daee065091b.zip
Fix some change detection issues on server reloads
* Fix change detection when .GetPage/site.GetPage is used from shortcode * Fix stale content for GetPage results with short name lookups on server reloads Fixes #7623 Fixes #7624 Fixes #7625
Diffstat (limited to 'identity')
-rw-r--r--identity/identity.go2
-rw-r--r--identity/identity_test.go51
2 files changed, 53 insertions, 0 deletions
diff --git a/identity/identity.go b/identity/identity.go
index ac3558d16..8fce16479 100644
--- a/identity/identity.go
+++ b/identity/identity.go
@@ -129,6 +129,8 @@ func (im *identityManager) Reset() {
im.Unlock()
}
+// TODO(bep) these identities are currently only read on server reloads
+// so there should be no concurrency issues, but that may change.
func (im *identityManager) GetIdentities() Identities {
im.Lock()
defer im.Unlock()
diff --git a/identity/identity_test.go b/identity/identity_test.go
index adebcad91..c315df1e7 100644
--- a/identity/identity_test.go
+++ b/identity/identity_test.go
@@ -14,6 +14,9 @@
package identity
import (
+ "fmt"
+ "math/rand"
+ "strconv"
"testing"
qt "github.com/frankban/quicktest"
@@ -29,6 +32,54 @@ func TestIdentityManager(t *testing.T) {
c.Assert(im.Search(testIdentity{name: "notfound"}), qt.Equals, nil)
}
+func BenchmarkIdentityManager(b *testing.B) {
+
+ createIds := func(num int) []Identity {
+ ids := make([]Identity, num)
+ for i := 0; i < num; i++ {
+ ids[i] = testIdentity{name: fmt.Sprintf("id%d", i)}
+ }
+ return ids
+
+ }
+
+ b.Run("Add", func(b *testing.B) {
+ c := qt.New(b)
+ b.StopTimer()
+ ids := createIds(b.N)
+ im := NewManager(testIdentity{"first"})
+ b.StartTimer()
+
+ for i := 0; i < b.N; i++ {
+ im.Add(ids[i])
+ }
+
+ b.StopTimer()
+ c.Assert(im.GetIdentities(), qt.HasLen, b.N+1)
+ })
+
+ b.Run("Search", func(b *testing.B) {
+ c := qt.New(b)
+ b.StopTimer()
+ ids := createIds(b.N)
+ im := NewManager(testIdentity{"first"})
+
+ for i := 0; i < b.N; i++ {
+ im.Add(ids[i])
+ }
+
+ b.StartTimer()
+
+ for i := 0; i < b.N; i++ {
+ name := "id" + strconv.Itoa(rand.Intn(b.N))
+ id := im.Search(testIdentity{name: name})
+ c.Assert(id.GetIdentity().Name(), qt.Equals, name)
+ }
+
+ })
+
+}
+
type testIdentity struct {
name string
}