From cf3faccd846835da5883b66687750b4666b40ea0 Mon Sep 17 00:00:00 2001 From: Will Sewell Date: Mon, 3 May 2021 15:58:33 +0100 Subject: [PATCH] Use lodash `chunk` to create batches Signed-off-by: Will Sewell --- plugins/catalog-react/src/hooks/useRelatedEntities.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/plugins/catalog-react/src/hooks/useRelatedEntities.ts b/plugins/catalog-react/src/hooks/useRelatedEntities.ts index 5649a90f52..25d96626d7 100644 --- a/plugins/catalog-react/src/hooks/useRelatedEntities.ts +++ b/plugins/catalog-react/src/hooks/useRelatedEntities.ts @@ -15,6 +15,7 @@ */ import { Entity } from '@backstage/catalog-model'; import { useApi } from '@backstage/core'; +import { chunk } from 'lodash'; import { useAsync } from 'react-use'; import { catalogApiRef } from '../api'; @@ -44,10 +45,7 @@ export function useRelatedEntities( // Make requests in separate batches to limit query string size // (there is a `filter` param for each relation) - const relationBatches = []; - for (let i = 0; i < relations.length; i += BATCH_SIZE) { - relationBatches.push(relations.slice(i, i + BATCH_SIZE)); - } + const relationBatches = chunk(relations, BATCH_SIZE); const results = await Promise.all( relationBatches.map(batch => {