aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2023-02-22 21:24:41 +0100
committerBjørn Erik Pedersen <[email protected]>2023-02-22 21:24:41 +0100
commit586fea0de6ea3d389ec6ccc893bdafcf3bc569a0 (patch)
treecac116261e9e84e16ecd51f076035bf6fcd514fc
parentfa2d7adf102d2dec9ebc52b5bc6b161bbb07b726 (diff)
downloadhugo-586fea0de6ea3d389ec6ccc893bdafcf3bc569a0.tar.gz
hugo-586fea0de6ea3d389ec6ccc893bdafcf3bc569a0.zip
page: Move the cache double check right after the lock
-rw-r--r--resources/page/pages_related.go10
1 files changed, 5 insertions, 5 deletions
diff --git a/resources/page/pages_related.go b/resources/page/pages_related.go
index 3378eb160..327369603 100644
--- a/resources/page/pages_related.go
+++ b/resources/page/pages_related.go
@@ -198,6 +198,11 @@ func (s *RelatedDocsHandler) getOrCreateIndex(ctx context.Context, p Pages) (*re
s.mu.Lock()
defer s.mu.Unlock()
+ // Double check.
+ if cachedIndex := s.getIndex(p); cachedIndex != nil {
+ return cachedIndex, nil
+ }
+
for _, c := range s.cfg.Indices {
if c.Type == related.TypeFragments {
// This will trigger building the Pages' fragment map.
@@ -219,11 +224,6 @@ func (s *RelatedDocsHandler) getOrCreateIndex(ctx context.Context, p Pages) (*re
break
}
-
- }
-
- if cachedIndex := s.getIndex(p); cachedIndex != nil {
- return cachedIndex, nil
}
searchIndex := related.NewInvertedIndex(s.cfg)