From 94ee9092cca191a1b8180f47d3c7a86c11a3c973 Mon Sep 17 00:00:00 2001 From: anatoleam Date: Fri, 15 Dec 2023 08:06:53 +0100 Subject: [PATCH] reduce batching of entitlements --- data/query/query.entitlements.go | 3 ++- internal/loaders/emoteset.loader.go | 5 ++--- internal/loaders/user.loader.go | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/data/query/query.entitlements.go b/data/query/query.entitlements.go index a5e7ec4d..760f7eeb 100644 --- a/data/query/query.entitlements.go +++ b/data/query/query.entitlements.go @@ -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" ) @@ -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) diff --git a/internal/loaders/emoteset.loader.go b/internal/loaders/emoteset.loader.go index fdf31fae..321f9c46 100644 --- a/internal/loaders/emoteset.loader.go +++ b/internal/loaders/emoteset.loader.go @@ -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() @@ -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, }) } diff --git a/internal/loaders/user.loader.go b/internal/loaders/user.loader.go index 299578c4..d460f9de 100644 --- a/internal/loaders/user.loader.go +++ b/internal/loaders/user.loader.go @@ -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()