Signed-off-by: Marco Pracucci <marco@pracucci.com>
This commit is contained in:
Marco Pracucci 2023-09-27 15:33:15 +02:00
parent 3c68ce252e
commit e2c1e7aadc
No known key found for this signature in database
GPG key ID: 74C1BD403D2DF9B5
2 changed files with 5 additions and 5 deletions

View file

@ -858,9 +858,9 @@ func NewPostingsCloner(p Postings) *PostingsCloner {
// so the returned slice capacity may be well above the actual number of items.
// In such case, we shrink it.
if float64(len(ids)) < float64(cap(ids))*0.70 {
shrinked := make([]storage.SeriesRef, len(ids))
copy(shrinked, ids)
ids = shrinked
shrunk := make([]storage.SeriesRef, len(ids))
copy(shrunk, ids)
ids = shrunk
}
return &PostingsCloner{ids: ids, err: err}

View file

@ -1108,13 +1108,13 @@ func TestNewPostingsCloner_ShrinkExpandedPostingsSlice(t *testing.T) {
t.Run("should not shrink expanded postings if length is >= 70% capacity", func(t *testing.T) {
cloner := NewPostingsCloner(NewListPostings(make([]storage.SeriesRef, 60)))
assert.Equal(t, 60, len(cloner.ids))
assert.Equal(t, 64, cap(cloner.ids)) // Not shrinked.
assert.Equal(t, 64, cap(cloner.ids)) // Not shrunk.
})
t.Run("should shrink expanded postings if length is < 70% capacity", func(t *testing.T) {
cloner := NewPostingsCloner(NewListPostings(make([]storage.SeriesRef, 33)))
assert.Equal(t, 33, len(cloner.ids))
assert.Equal(t, 33, cap(cloner.ids)) // Shrinked.
assert.Equal(t, 33, cap(cloner.ids)) // Shrunk.
})
}