Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON-API adapter not grouping together relationship-gets for coalescing #3899

Closed
mwpastore opened this issue Oct 31, 2015 · 9 comments
Closed

Comments

@mwpastore
Copy link
Contributor

I have an API endpoint /api/foos that returns a collection of Foos. Each Foo belongsTo a (has one) Bar, and the related link comes over in the JSON-API payload as /api/bars/N where N is the ID of the Bar. When I iterate over the collection of Foos in my template and call foo.get('bar'), Ember Data dispatches many requests to the backend, one for each Bar. This is undesirable.

I have namespace set to /api and coalesceFindRequests set to true in my ApplicationAdapter. Digging into the JSON-API and REST adapters' code a bit, I would expect groupRecordsForFindMany to map this sequence of similar requests to a single request with a list of Bar IDs. Either this function isn't being called or it isn't working correctly. Or it's possible I'm not using Ember Data correctly!

Any suggestions on where to go from here? Is this an actual bug or missing feature or PEBKAC? Thanks in advance.

@bmac
Copy link
Member

bmac commented Nov 2, 2015

This sounds like a bug. @igorT can you confirm that coalesceFindRequests should coalesce async relationship requests?

@zachzhao1984
Copy link

@bmac in my project, coalesceFindRequests can coalesce async relationship requests, but in ?filter[id]=180,181,260,262,263,282,290 format, not like id[]=1&id[]=2&id[]=3

@mwpastore
Copy link
Contributor Author

@nouh: That's just the JSON-API-compliant behavior I'm looking for! Did you have to do anything to get it working (besides setting coalesceFindRequests to true in your ApplicationAdapter)? What versions of Ember and Ember Data are you on and what does your JSON-API payload look like?

@mwpastore
Copy link
Contributor Author

@runspired suggests that this might be because these are belongsTo relationships and findBelongsTo does not invoke groupRecordsForFindMany when resolving. Thoughts on this and how I might implement that?

@mukk85
Copy link

mukk85 commented Mar 8, 2021

@mwpastore Were you ever able to resolve this? I am running into the same issue now

@mukk85
Copy link

mukk85 commented Mar 8, 2021

It looks like in my case it is because my back end is sending links and data and ember-data prioritizes the links.

@runspired
Copy link
Contributor

@mukk85 we can't easily group link requests, however you probably can if you implement findBelongsTo / findHasMany.

@mukk85
Copy link

mukk85 commented May 22, 2021

@runspired I know we cant group link requests, but can we have it so it prioritizes IDs if the data is provided?

@runspired
Copy link
Contributor

With the RequestManager RFC emberjs/rfcs#860 coalescing and request-management become fully customizable to handle fulfillment and could coalesce on ids even when links are present.

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

No branches or pull requests

6 participants