How can I limit and show only the first referenced node per node in a view? I have content type A with a field that references nodes of type B. This is field with multiple values.

I need to show all the values of content type A, and include one of the fields of the referenced content type B (an image). So I created a view showing these fields.

The problem is that I just want to show the first result of content type B and eliminate the duplicates of content type A. So according to the post Only show first entity reference in views, I used the module Views Distinct. And it works, the problem is that I have more than 2000 nodes and the query is very very slow.

So the next thing I thought was to use the Infinite Scroll module to make it faster. And this works, but the problem now is that I need to group the results by a field, and with this module the header of each group is being repeated, every time results are loaded.

So I thought I could use the Delta for the reference field, and filter it to the nodes with delta = 0, but I don't know why the first value is not 0 is a different number. So this option is not valid.

Does anyone know how to show only the first reference with a good performance?
I can suggest you one solution which will probably help you with performance.

You can make use of views field view module.

You can use the view which you have created to render the fields of content type A and now create a separate view (as block) of content type B with current node ID as contextual filter and required relationship for the reference field and set limit to 1 or use delta as filter and call this view as field in the view in which you have rendered content type A fields.

EDIT: Second view can be called conditionaly wherever required, so is more handy if you require it only once in the parent view (by result count or once in header) OR get rendered it with every result of parent view.