Skip to content

Commit df757ca

Browse files
authored
fix: don't use collation for FindAllByReqHash (#153)
1 parent 8af9076 commit df757ca

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

.github/workflows/dependabot.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Dependabot mod & vendor fix
1+
name: Dependabot mod fix
22
on:
33
push:
44
branches:

internal/flaggio/distribution.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ func (dl DistributionList) Evaluate(usrContext map[string]interface{}) (EvalResu
3535

3636
// Distribute selects a distribution randomly, respecting the configured probability.
3737
func (dl DistributionList) Distribute() *Variant {
38-
r1 := rand.New(rand.NewSource(time.Now().UnixNano()))
39-
num := 1 + r1.Intn(100) // random int between 1 and 100
38+
r1 := rand.New(rand.NewSource(time.Now().UnixNano())) // nolint:gosec // not security critical
39+
num := 1 + r1.Intn(100) // random int between 1 and 100
4040

4141
var total int
4242
for _, dstrbtn := range dl {

internal/repository/mongodb/evaluation.repository.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ func (r *EvaluationRepository) FindAllByReqHash(ctx context.Context, reqHash str
7777

7878
filter := bson.M{"requestHash": reqHash}
7979
cursor, err := r.col.Find(ctx, filter, &options.FindOptions{
80-
Sort: bson.M{"flagKey": 1},
81-
Collation: &options.Collation{Locale: "en"},
80+
Sort: bson.M{"flagKey": 1},
8281
})
8382
if err != nil {
8483
return nil, err
@@ -242,6 +241,14 @@ func NewEvaluationRepository(ctx context.Context, db *mongo.Database) (repositor
242241
Keys: bson.D{{Key: "userId", Value: 1}, {Key: "flagId", Value: 1}},
243242
Options: options.Index().SetUnique(true).SetBackground(false),
244243
},
244+
{
245+
Keys: bson.D{{Key: "requestHash", Value: 1}},
246+
Options: options.Index().SetBackground(true),
247+
},
248+
{
249+
Keys: bson.D{{Key: "flagId", Value: 1}},
250+
Options: options.Index().SetBackground(true),
251+
},
245252
})
246253
if err != nil {
247254
return nil, err

0 commit comments

Comments
 (0)