Skip to content
This repository has been archived by the owner on Nov 27, 2020. It is now read-only.

Commit

Permalink
fix: don't use collation for FindAllByReqHash (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
victorkt authored Oct 19, 2020
1 parent 8af9076 commit df757ca
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Dependabot mod & vendor fix
name: Dependabot mod fix
on:
push:
branches:
Expand Down
4 changes: 2 additions & 2 deletions internal/flaggio/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func (dl DistributionList) Evaluate(usrContext map[string]interface{}) (EvalResu

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

var total int
for _, dstrbtn := range dl {
Expand Down
11 changes: 9 additions & 2 deletions internal/repository/mongodb/evaluation.repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ func (r *EvaluationRepository) FindAllByReqHash(ctx context.Context, reqHash str

filter := bson.M{"requestHash": reqHash}
cursor, err := r.col.Find(ctx, filter, &options.FindOptions{
Sort: bson.M{"flagKey": 1},
Collation: &options.Collation{Locale: "en"},
Sort: bson.M{"flagKey": 1},
})
if err != nil {
return nil, err
Expand Down Expand Up @@ -242,6 +241,14 @@ func NewEvaluationRepository(ctx context.Context, db *mongo.Database) (repositor
Keys: bson.D{{Key: "userId", Value: 1}, {Key: "flagId", Value: 1}},
Options: options.Index().SetUnique(true).SetBackground(false),
},
{
Keys: bson.D{{Key: "requestHash", Value: 1}},
Options: options.Index().SetBackground(true),
},
{
Keys: bson.D{{Key: "flagId", Value: 1}},
Options: options.Index().SetBackground(true),
},
})
if err != nil {
return nil, err
Expand Down

0 comments on commit df757ca

Please sign in to comment.