Skip to content

Conversation

jhb-dev
Copy link
Contributor

@jhb-dev jhb-dev commented Sep 17, 2025

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 theRelationshipCell 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

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.

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?

This would be a breaking change if someone were using the useListRelationships hook, e.g. #8568 — but we can just make this conditional based on the new enableListViewSelectAPI property.

@jacobsfletch
Copy link
Member

Also quick response here:

For upload enabled collections, the full document must be requested, because the relationship cell needs access to fields like mimeType, thumbailURL etc.

There might be a way to determine upload-specific fields and only select those. Worth exploring.

@jhb-dev jhb-dev changed the title perf(ui): only select the useAsTitle field when fetching the documents in the RelationshipProvider perf(ui): use select API in RelationshipProvider to speed up load times in RelationshipCell Sep 18, 2025
@jhb-dev
Copy link
Contributor Author

jhb-dev commented Sep 18, 2025

Thanks for the prompt response, @jacobsfletch. I just made the requested changes!

@jacobsfletch jacobsfletch merged commit 77cac30 into payloadcms:main Sep 19, 2025
168 of 170 checks passed
const fieldToSelect = collection.admin.useAsTitle ?? 'id'
select[fieldToSelect] = true

if (collection.upload) {
Copy link
Contributor

@JarrodMFlesch JarrodMFlesch Sep 19, 2025

Choose a reason for hiding this comment

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

@jhb-dev we could remove this line (L78), the helper util already checks this condition internally.

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

Successfully merging this pull request may close these issues.

3 participants