Skip to content

Commit 7e57706

Browse files
committed
Update contains method
1 parent 69fcf02 commit 7e57706

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

storage/inmemory/mutexmap/rulebasedsegment.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,16 @@ func (r *RuleBasedSegmentsStorageImpl) GetSegments() *set.ThreadUnsafeSet {
101101
return segments
102102
}
103103

104-
// Contains returns true or false if all the segment names are in the rule-based segments
104+
// Contains returns true or false if all the rule-based segment names are present
105105
func (r *RuleBasedSegmentsStorageImpl) Contains(ruleBasedSegmentNames []string) bool {
106106
if len(ruleBasedSegmentNames) == 0 {
107107
return false
108108
}
109-
segments := r.GetSegments()
109+
r.mutex.RLock()
110+
defer r.mutex.RUnlock()
110111
for _, name := range ruleBasedSegmentNames {
111-
if !segments.Has(name) {
112+
_, exists := r.data[name]
113+
if !exists {
112114
return false
113115
}
114116
}

storage/inmemory/mutexmap/rulebasedsegment_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ func TestRuleBasedSegmentsStorage(t *testing.T) {
7979
assert.True(t, segments.Has("excluded1"), "excluded1 should be in segments")
8080

8181
// Test Contains
82-
assert.True(t, storage.Contains([]string{"segment1", "excluded1"}), "should contain segment1 and excluded1")
83-
assert.True(t, storage.Contains([]string{"segment2"}), "should contain segment2")
82+
assert.True(t, storage.Contains([]string{"rule1", "rule2"}), "should contain rule1 and rule2")
83+
assert.True(t, storage.Contains([]string{"rule1"}), "should contain rule1")
8484
assert.False(t, storage.Contains([]string{"nonexistent"}))
8585

8686
// Test Remove

0 commit comments

Comments
 (0)