Skip to content

Commit

Permalink
page: Move the cache double check right after the lock
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Feb 22, 2023
1 parent fa2d7ad commit 586fea0
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions resources/page/pages_related.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down

0 comments on commit 586fea0

Please sign in to comment.