From 99e6105d1e97a2e38302b6144dda1a23c1506529 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Tue, 30 Apr 2024 11:27:27 +0200 Subject: [PATCH] Fix ownership card sometimes locking up for complex org structures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- .changeset/wet-files-pretend.md | 5 +++++ .../Cards/OwnershipCard/useGetEntities.ts | 22 +++++++++---------- 2 files changed, 16 insertions(+), 11 deletions(-) create mode 100644 .changeset/wet-files-pretend.md diff --git a/.changeset/wet-files-pretend.md b/.changeset/wet-files-pretend.md new file mode 100644 index 0000000000..8f77a5bc0b --- /dev/null +++ b/.changeset/wet-files-pretend.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-org': patch +--- + +Fix ownership card sometimes locking up for complex org structures diff --git a/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.ts b/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.ts index e7c1f132c3..5a708bcfee 100644 --- a/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.ts +++ b/plugins/org/src/components/Cards/OwnershipCard/useGetEntities.ts @@ -34,7 +34,7 @@ import qs from 'qs'; import { EntityRelationAggregation } from '../types'; import { uniq } from 'lodash'; -const limiter = limiterFactory(10); +const limiter = limiterFactory(5); type EntityTypeProps = { kind: string; @@ -92,10 +92,12 @@ const getChildOwnershipEntityRefs = async ( const entityRef = stringifyEntityRef(entity); if (hasChildGroups) { const entityRefs = childGroups.map(r => stringifyEntityRef(r)); - const childGroupResponse = await catalogApi.getEntitiesByRefs({ - fields: ['kind', 'metadata.namespace', 'metadata.name', 'relations'], - entityRefs, - }); + const childGroupResponse = await limiter(() => + catalogApi.getEntitiesByRefs({ + fields: ['kind', 'metadata.namespace', 'metadata.name', 'relations'], + entityRefs, + }), + ); const childGroupEntities = childGroupResponse.items.filter(isEntity); const unknownChildren = childGroupEntities.filter( @@ -107,12 +109,10 @@ const getChildOwnershipEntityRefs = async ( const childrenRefs = ( await Promise.all( unknownChildren.map(childGroupEntity => - limiter(() => - getChildOwnershipEntityRefs(childGroupEntity, catalogApi, [ - ...alreadyRetrievedParentRefs, - entityRef, - ]), - ), + getChildOwnershipEntityRefs(childGroupEntity, catalogApi, [ + ...alreadyRetrievedParentRefs, + entityRef, + ]), ), ) ).flatMap(aggregated => aggregated);