Skip to content

Conversation

jhb-dev
Copy link
Contributor

@jhb-dev jhb-dev commented Jul 21, 2025

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.

Related: #12251

@jacobsfletch
Copy link
Member

We've explored this in the past but unfortunately this would be considered a breaking change as users consuming this component might be currently relying on fully populated data. This would have to be made opt-in.

@jhb-dev
Copy link
Contributor Author

jhb-dev commented Jul 22, 2025

Thanks for the quick response, @jacobsfletch. I just pushed a commit to make this performance optimization opt-in at the relationship field level via a new populateDocumentTitleOnly option.
Please let me know if you have any feedback or would prefer a different name or approach.

@jacobsfletch
Copy link
Member

jacobsfletch commented Jul 28, 2025

@jhb-dev I meant opt-in at the component-level, not on the config. Buuut after looking into this further, we only ever dispatch the document ID to the onChange handlers and ultimately form state. We no longer expose the full document data, so I think this is a safe change to make after all!

…p field to ensure backwards compatability"

This reverts commit 71ed479.
@jhb-dev
Copy link
Contributor Author

jhb-dev commented Jul 30, 2025

Thanks, @jacobsfletch, that's great! I've reverted the commit that added the opt-in.

@JarrodMFlesch
Copy link
Contributor

@jacobsfletch 👀

Copy link
Member

@jacobsfletch jacobsfletch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @jhb-dev

@jacobsfletch jacobsfletch merged commit 1b31c74 into payloadcms:main Aug 1, 2025
163 of 166 checks passed
jacobsfletch pushed a commit that referenced this pull request Sep 19, 2025
…es in RelationshipCell (#13832)

### What?
Optimize the `RelationshipProvider` to only select the `useAsTitle`
field when fetching documents via the REST API. This reduces payload
size and speeds up loading of the related document title in
the`RelationshipCell` in the table view.

### Why?
Previously, when a document had a relationship field, the full document
data was requested in the table view, even though the relationship cell
only shows the title in the UI. On large collections, this caused
unnecessary overhead and slower UI performance.

### How?
Applies a select to the REST API request made in the
`RelationshipProvider`, limiting the responses to the `useAsTitle` field
only.

### Notes
- I’m not entirely sure whether this introduces a breaking change. If it
does, could you suggest a way to make this behavior opt-in?
- For upload enabled collections, the full document must be requested,
because the relationship cell needs access to fields like `mimeType`,
`thumbailURL` etc.
- I hope we can find a way to get this merged. In the Payload projects I
work on, this change has significantly improved list view performance.


Similar to #13228
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants