From 4055c121847847d8bd6b95a928185daee065091b Mon Sep 17 00:00:00 2001 From: Bjørn Erik Pedersen Date: Mon, 7 Sep 2020 15:07:10 +0200 Subject: 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 --- identity/identity.go | 2 ++ identity/identity_test.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) (limited to 'identity') 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 } -- cgit v1.2.3