-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Ember Data is using the links in relationships, not using data in relationships #5574
Comments
@fengshuo if you give us a link, we will always use the link when fetching.
This is still true; however, this probably doesn't mean what you think. It refers to when you have previously loaded a record with that |
I do think this behavior has changed after 3.1. In our app, with ED 3.1, for a hasMany relationship with included IDs and a link, it would load the relationship via the IDs initially. Later, if I'd call e.g. For us, this is a very useful functionality, as we can reduce the number of requests initially, while still being able to later reload the relationship. As far as I see, this is not really possible (easily) anymore in 3.4. Now, it will always use the link to fetch the relationship - which works, but leads to many more API requests. A concrete example: On a page, we load the hasMany relationship for a model, which returns n items. let items = await get(model, 'items');
await RSVP.all(items.mapBy('subItems')); Previously, this would result in 2 API requests:
After upgrading to ED 3.4, it results in 1 + n requests, where n is the number of items - as it will fetch the included link, one by one. Right now, the only way forward I see is either a) living with a huge amount of API requests or b) manually removing the link information in the For me, the old behavior made more sense:
(Maybe I'm missing something, but this has changed the behavior of our app in subtle ways that were hard to track down and lead to unexpected performance regressions) |
@mydea I suspect either you aren't normalizing your data correctly or the relationships in your payloads are less defined than they should be. Here is the behavior you should observe: 1.) No requests Made: (
2.) A single "links" request made (
3.) A single "links" request made (
4.) One or more "data" requests made (
|
We are in this case using variant 2 ( a) a not-so-trivial change in behavior Yes, links are conceptually nice, but we specifically added the IDs in this (and some other cases) in our apps because we wanted to avoid triggering literally hundreds of simultaneous API requests at the same time. |
@mydea using data instead of links is what would cause you to fire extra requests... links ensures the fewest possible... |
Not when using Let's take this example (simplified): let model = {
id: 'XX',
items: [
{ id: 'A', subItems: [1, 2] },
{ id: 'B', subItems: [3] },
{ id: 'C', subItems: [4, 5] }
]
} Where the subItems are hasMany relationships with the given IDs, which are specified with both
With data, we get two requests when starting out from
With links, we get 4:
This is a very simplified example - in our case, this often ends up with hundreds of requests. I hope this helps to clarify what I mean! |
So the nice thing about how things have improved in ember-data since the 2.x days is that now you can choose :) Implement findHasMany and call findMany with the IDs instead of the link. The hope is that the ID only case will do just that by default soon anyway. |
I would also suggest that using includes or fastboot shoebox both seem like better solutions here than coalesceFindRequests. |
I actually tried that, but the problem here is that
Also, including it would be nice, but this is not that easy when working with relationships. In this example, We can of course try to somehow include everything up front, but this then leads to one giant API request which blocks rendering of the whole page, which also doesn't really feel nice, and requires us to constantly think about this, whereas previously it would just work pretty nicely by default. I guess my main question is, if we include IDs, why shouldn't we use it and instead use the link? I don't quite understand why this should be the preferred way from an API perspective. Maybe if Since this default has basically changed silently after ED 3.1, it would be nice to have a concrete recommended solution for this. IMHO, forcing us to use |
@mydea if you want to ick up the torch on this RFC and ensure that Here is a twiddle showing how using It's less nice than I would like because |
@mydea and here is an example coalescing within the adapter itself: https://ember-twiddle.com/597ff8ccc4e9a06ff26c1754ba108fb3?openFiles=adapters.application.js%2C |
Hi,
I have an jsonapi response (
/contents
) with this format:one provider may have many contents, the models has the
hasMany
andbelongsTo
relationship setup. The issue is that when requesting providers information, ember data is not using thedata
insiderelationships
, but using thelinks
inrelationships
.I read in several places that ember data will use the
data
inside relationship if it exists, such as here and here, I wonder if ember data 3.3 is still working like this?Thanks.
The text was updated successfully, but these errors were encountered: