page: Move the cache double check right after the lock

This commit is contained in:
Bjørn Erik Pedersen 2023-02-22 21:24:41 +01:00
parent fa2d7adf10
commit 586fea0de6
No known key found for this signature in database
GPG key ID: 330E6E2BD4859D8F

View file

@ -198,6 +198,11 @@ func (s *RelatedDocsHandler) getOrCreateIndex(ctx context.Context, p Pages) (*re
s.mu.Lock() s.mu.Lock()
defer s.mu.Unlock() defer s.mu.Unlock()
// Double check.
if cachedIndex := s.getIndex(p); cachedIndex != nil {
return cachedIndex, nil
}
for _, c := range s.cfg.Indices { for _, c := range s.cfg.Indices {
if c.Type == related.TypeFragments { if c.Type == related.TypeFragments {
// This will trigger building the Pages' fragment map. // This will trigger building the Pages' fragment map.
@ -219,11 +224,6 @@ func (s *RelatedDocsHandler) getOrCreateIndex(ctx context.Context, p Pages) (*re
break break
} }
}
if cachedIndex := s.getIndex(p); cachedIndex != nil {
return cachedIndex, nil
} }
searchIndex := related.NewInvertedIndex(s.cfg) searchIndex := related.NewInvertedIndex(s.cfg)