Requests triggering multiple times


#1

I started an update to Ember Data 1.0.0-beta.10 but have run into some significant performance issues. The most important being the fact that multiple requests are being triggered whenver I use a property in the template that is a relationship.

For example:

A Customer hasMany Events in our application.

In my template I use a collection view to render these events:

{{view ‘some/collection’ content=events}}

The property events is directly on an ObjectController. If I want to render the events in two collections, on the same page - I get 4 requests (2 OPTIONS and 2 GET).

I’ve detailed a stackoverflow issue here, but I’m hoping to get some help with this. I’ve used ember-data and ember for a while but I haven’t come across this issue. As soon as I rollback to 1.0.0-beta.9 everything works fine.


#2

Any chance you could submit a jsbin that reproduces the issue? There is a good template ED jsbin here -> https://github.com/emberjs/data/blob/master/CONTRIBUTING.md


#3

@terzicigor For sure! I had no idea there was a template for that. Either way, I’ve created one here:

http://emberjs.jsbin.com/xunuqa/1/

But unfortunately I can’t seem to make it work right. It looks like its still hitting the jsbin domain. I think it has something to do with the use of links? Not really sure, any help here would be appreciated - I definitely want to help out if I find a bug and I know that a demo is super useful.


#4

Your mockjax url was wrong, you were setting it to /customer/1 but the app was going to /customers/1 Here is a version where I fixed that ->


#5

@terzicigor Thanks for helping me out on that - I was pretty exhausted after a whole day of ember data updates to our app. I apologize for my mistake.

I was able to reproduce the issue here: http://jsbin.com/moruj/1/

And here is the same code using beta.9: http://jsbin.com/sevive/1/edit


#6

Yup, definitely a bug. Working on a fix.


#7

Any feedback from updating other than this bug?


#8

Thanks for asking!

The upgrade was going straight forward, except I found myself having to update some relationships that were working previously. For example, we have a model that references itself:

App.Metric = DS.Model.extend({
    daily: DS.belongsTo('metric'),
    weekly: DS.belongsTo('metric')
});

When I updated I got some errors that required me to change it to:

App.Metric = DS.Model.extend({
    daily: DS.belongsTo('metric', { inverse: 'daily' }),
    weekly: DS.belongsTo('metric', { inverse: 'weekly' })
});

In those cases, I figured it out pretty quickly - but I would expect that to be a deprecation instead of an error - so that the app could continue to run even if the inverse was not set. I ran into this issue with having to set { async: true } as well. Getting an error instead of a warning or deprecation of some kind.

Other than that - the only really confusing/frustrating part was this bug - because I had thought that we were doing something really out of the ordinary and didn’t come up with any results on Google.

Let me know if I can help in any way!


#9

We could actually be clever and detect if the inverse is to itself and just return the same key by default. Wanna file a bug?


#10

Yeah sure :smile:! That sounds good to me.


#11

This actually turned out to be a subtle issue, mainly due to the fact that bindings are sync, but should be solved in a proper way anyhow.


#12

Was there a github issue or pr that I could follow? I’d just like to learn more about it.


#13

I have tests passing on this branch: https://github.com/emberjs/data/tree/findHasManyMultipleTimes Need to cleanup and refactor and will merge then.


#14

I merged the fix to master.