Skip to content

Commit 1b31c74

Browse files
authored
perf(ui): only select the useAsTitle field when fetching the document data of a relationship value (#13228)
### What? Optimize the relationship value loading by selecting only the `useAsTitle` field when fetching document data via the REST API. ### Why? Previously, all fields were fetched via a POST request when loading the document data of a relationship value, causing unnecessary data transfer and slower performance. Only the `useAsTitle` field is needed to display the related document’s title in the relationship UI field. ### How? Applied a select to the REST API POST request, similar to how the options list is loaded, limiting the response to the `useAsTitle` field only.
1 parent f432cc1 commit 1b31c74

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

packages/ui/src/fields/Relationship/Input.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,11 +413,17 @@ export const RelationshipInput: React.FC<RelationshipInputProps> = (props) => {
413413
})
414414

415415
if (idsToLoad.length > 0) {
416+
const collection = getEntityConfig({ collectionSlug: relation })
417+
const fieldToSelect = collection?.admin?.useAsTitle || 'id'
418+
416419
const query = {
417420
depth: 0,
418421
draft: true,
419422
limit: idsToLoad.length,
420423
locale,
424+
select: {
425+
[fieldToSelect]: true,
426+
},
421427
where: {
422428
id: {
423429
in: idsToLoad,
@@ -436,8 +442,6 @@ export const RelationshipInput: React.FC<RelationshipInputProps> = (props) => {
436442
},
437443
method: 'POST',
438444
})
439-
440-
const collection = getEntityConfig({ collectionSlug: relation })
441445
let docs = []
442446

443447
if (response.ok) {

0 commit comments

Comments
 (0)