ash-project / ash_json_api

The JSON:API extension for the Ash Framework
https://hexdocs.pm/ash_json_api
MIT License
55 stars 41 forks source link

fix: fix issue with includes being duplicated when relationships overlap #156

Closed jsw800 closed 1 month ago

jsw800 commented 2 months ago

I noticed this issue with includes, which it turns out an existing test was already replicating, although there were no asserts in that test, so it wasn't getting caught.

Basically, if multiple different items in the response are all related to the same related resource, then that resource will show up multiple times in the included array.

In certain scenarios, this can cause response sizes to balloon pretty dramatically. In an example in my own application, I was including across a belongs_to and a has_many, and the response had ~30k elements in the includes, but after collapsing down to unique elements, there are actually only ~2100 unique elements.

The solution here is to get unique values by type + id in the includes list, while merging linkages from the distinct elements.

Contributor checklist

zachdaniel commented 1 month ago

Closing in favor of https://github.com/ash-project/ash_json_api/pull/158