From 6d1d44e207eb9343e11370ef38d784265739aec8 Mon Sep 17 00:00:00 2001 From: Ezra Smith Date: Thu, 19 Oct 2023 22:21:45 -0400 Subject: [PATCH] Add a comment --- cmd/dataloaders/generator/dataloader.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/dataloaders/generator/dataloader.go b/cmd/dataloaders/generator/dataloader.go index e7c6b2e05..261e7f101 100644 --- a/cmd/dataloaders/generator/dataloader.go +++ b/cmd/dataloaders/generator/dataloader.go @@ -253,6 +253,9 @@ func (d *Dataloader[TKey, TResult]) addKeyToBatch(key TKey, jsonKey string) (*ba } b := actual.(*batch[TKey, TResult]) + + // Prevent lock contention within a batch by allowing only the first maxBatchSize callers + // to obtain the lock. numAssigned := atomic.AddInt32(&b.numAssigned, 1) if numAssigned > int32(d.maxBatchSize) { atomic.CompareAndSwapInt32(&d.currentBatchID, currentID, currentID+1)