@@ -110,12 +110,6 @@ type SegmentBase struct {
110
110
111
111
m sync.Mutex
112
112
fieldFSTs map [uint16 ]* vellum.FST
113
-
114
- docIDMutex sync.RWMutex
115
- // cache the maximum docID seen in this segment
116
- cachedMaxDocID string
117
- //cache the dictionary for the _id field
118
- idDict * Dictionary
119
113
}
120
114
121
115
func (sb * SegmentBase ) Size () int {
@@ -587,57 +581,26 @@ func (s *SegmentBase) Count() uint64 {
587
581
return s .numDocs
588
582
}
589
583
590
- func (s * SegmentBase ) getDocIDinfo () (* Dictionary , string , error ) {
591
- // obtain a read lock to check if the max doc ID and dict for _id is cached
592
- s .docIDMutex .RLock ()
593
- cachedDocID := s .cachedMaxDocID
594
- cachedDict := s .idDict
595
- if cachedDocID != "" && cachedDict != nil {
596
- s .docIDMutex .RUnlock ()
597
- // max doc ID and the id dict is cached, return it
598
- return cachedDict , cachedDocID , nil
599
- }
600
- s .docIDMutex .RUnlock ()
601
- // not cached so obtain a write lock
602
- // to create the _id dict and read the FST
603
- // to get the max doc id and cache them
604
- s .docIDMutex .Lock ()
605
- defer s .docIDMutex .Unlock ()
606
- // check if the info is cached again
607
- // by some other thread to avoid unnecessary
608
- // ops.
609
- if s .idDict != nil && s .cachedMaxDocID != "" {
610
- return s .idDict , s .cachedMaxDocID , nil
611
- }
612
- // create the _id dict
613
- idDict , err := s .dictionary ("_id" )
614
- if err != nil {
615
- return nil , "" , err
616
- }
617
- s .idDict = idDict
618
- // max doc ID is not cached, get it from the FST
619
- sMax , err := idDict .fst .GetMaxKey ()
620
- if err != nil {
621
- return nil , "" , err
622
- }
623
- // cache it
624
- s .cachedMaxDocID = string (sMax )
625
- return s .idDict , s .cachedMaxDocID , nil
626
- }
627
-
628
584
// DocNumbers returns a bitset corresponding to the doc numbers of all the
629
585
// provided _id strings
630
586
func (s * SegmentBase ) DocNumbers (ids []string ) (* roaring.Bitmap , error ) {
631
587
rv := roaring .New ()
632
588
633
589
if len (s .fieldsMap ) > 0 {
590
+ idDict , err := s .dictionary ("_id" )
591
+ if err != nil {
592
+ return nil , err
593
+ }
594
+
634
595
postingsList := emptyPostingsList
635
- idDict , maxDocID , err := s .getDocIDinfo ()
596
+
597
+ sMax , err := idDict .fst .GetMaxKey ()
636
598
if err != nil {
637
599
return nil , err
638
600
}
601
+ sMaxStr := string (sMax )
639
602
for _ , id := range ids {
640
- if id <= maxDocID {
603
+ if id <= sMaxStr {
641
604
postingsList , err = idDict .postingsList ([]byte (id ), nil , postingsList )
642
605
if err != nil {
643
606
return nil , err
0 commit comments