feat(catalog): only fetch needed fields for entity presentation

To save bandwidth, only fetch the necessary fields for the entity
presentation API for displaying the entity title.

Signed-off-by: Heikki Hellgren <heikki.hellgren@op.fi>
This commit is contained in:
Heikki Hellgren
2024-08-07 10:09:01 +03:00
parent 7ac69f7633
commit 180a45ffa5
3 changed files with 25 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog': patch
---
Entity presentation api now only fetches fields that are required to display entity title
@@ -161,6 +161,15 @@ describe('DefaultEntityPresentationApi', () => {
expect(catalogApi.getEntitiesByRefs).toHaveBeenCalledWith(
expect.objectContaining({
entityRefs: ['component:default/test'],
fields: [
'kind',
'metadata.name',
'metadata.namespace',
'metadata.title',
'metadata.description',
'spec.profile.displayName',
'spec.type',
],
}),
);
});
@@ -26,15 +26,15 @@ import {
EntityRefPresentation,
EntityRefPresentationSnapshot,
} from '@backstage/plugin-catalog-react';
import { HumanDuration, durationToMilliseconds } from '@backstage/types';
import { durationToMilliseconds, HumanDuration } from '@backstage/types';
import DataLoader from 'dataloader';
import ExpiryMap from 'expiry-map';
import ObservableImpl from 'zen-observable';
import {
createDefaultRenderer,
DEFAULT_BATCH_DELAY,
DEFAULT_CACHE_TTL,
DEFAULT_ICONS,
createDefaultRenderer,
} from './defaults';
/**
@@ -371,6 +371,15 @@ export class DefaultEntityPresentationApi implements EntityPresentationApi {
async (entityRefs: readonly string[]) => {
const { items } = await options.catalogApi!.getEntitiesByRefs({
entityRefs: entityRefs as string[],
fields: [
'kind',
'metadata.name',
'metadata.namespace',
'metadata.title',
'metadata.description',
'spec.profile.displayName',
'spec.type',
],
});
const now = Date.now();