Skip to content

Commit

Permalink
reduce batching of entitlements
Browse files Browse the repository at this point in the history
  • Loading branch information
AnatoleAM committed Dec 15, 2023
1 parent c47b8c8 commit 94ee909
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
3 changes: 2 additions & 1 deletion data/query/query.entitlements.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/seventv/common/utils"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo/options"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -61,7 +62,7 @@ func (q *Query) Entitlements(ctx context.Context, filter bson.M, opts ...QueryEn
"emote_sets": typeFilterFactory(structures.EntitlementKindEmoteSet, mongo.CollectionNameEmoteSets, false),
},
}},
})
}, options.Aggregate().SetBatchSize(10))
if err != nil {
zap.S().Errorw("failed to query entitlements", "error", err)
r.setError(err)
Expand Down
5 changes: 2 additions & 3 deletions internal/loaders/emoteset.loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

func emoteSetByID(ctx context.Context, x inst) EmoteSetLoaderByID {
return dataloader.New(dataloader.Config[primitive.ObjectID, structures.EmoteSet]{
Wait: time.Millisecond * 100,
Wait: time.Millisecond * 25,
Fetch: func(keys []primitive.ObjectID) ([]structures.EmoteSet, []error) {
ctx, cancel := context.WithTimeout(ctx, time.Second*30)
defer cancel()
Expand Down Expand Up @@ -53,8 +53,7 @@ func emoteSetByID(ctx context.Context, x inst) EmoteSetLoaderByID {

return models, errs
},
// TODO: find optimal max batch size
MaxBatch: 30,
MaxBatch: 10,
})
}

Expand Down
4 changes: 2 additions & 2 deletions internal/loaders/user.loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ func userByConnectionLoader(ctx context.Context, x inst, platform structures.Use

func entitlementsLoader(ctx context.Context, x inst) *dataloader.DataLoader[primitive.ObjectID, query.EntitlementQueryResult] {
return dataloader.New(dataloader.Config[primitive.ObjectID, query.EntitlementQueryResult]{
Wait: time.Millisecond * 100,
MaxBatch: 500,
Wait: time.Millisecond * 25,
MaxBatch: 10,
Fetch: func(keys []primitive.ObjectID) ([]query.EntitlementQueryResult, []error) {
ctx, cancel := context.WithTimeout(ctx, time.Second*30)
defer cancel()
Expand Down

0 comments on commit 94ee909

Please sign in to comment.