When adding records just after loading them, the elements in the UI
might have to be updated, which may trigger `get` on associations right
away. As an effect, even if we load a few records on an event (like
repository on build:started event), ember model may end up fetching the
record.
This commit fixes such occurrences by adding record to record arrays in
a run loop, so newly created records will be added at once, after the
event was served.
Previousy I was using find to ensure that the record is materialized,
but the new version is much lighter - it uses Model#load to load the
record directly
When using get with path (eg. get('foo.bar.baz')), get method is called
only on the current object and computed property will be called. Because
there is no easy way to overwrite the computed property, I moved
incomplete record loading to ember-data. It's not DRY and it should be
rewritten, but I don't want to do it at this point as we will need to
completely rewrite it when upgrading ember-data.
While testing in the wild I spotted a few problems with it:
* it didn't work for camel case names.
* it was sometimes setting loaded data too late - it needed to use find
and then save data on the record. Instead it should save data in
special array saved on store, indexed by clientId
* there is already method to get attributes in ember-data, it just
doesn't work with Travis.Foo.get('attributes'), it needs
Ember.get(Travis.Foo, 'attributes') - it makes implementation much
shorter
In order to minimize ajax requests, I implemented isComplete property,
which can be used to check if record is fetched from the API or if it
was just partially loaded (for example by pusher event). This is nice in
terms of requests reduction, but caries risk of showing incomplete data.
This commit fixes this situation by saving which attributes were
provided on "incomplete" load and triggering refresh when any unknown
attribute is tried to be fetched.
The implementation is really simple and will probably need refactoring,
but I would like to test it in the wild before putting much more time
into it.
When we get payload from pusher, we usually don't send the entire
record. Initially such records where fetched from server right away to
get missing data. This was done becuase Ember can't tell if given data
is complete or not and just assumes that the record is loaded.
To not fire unneeded request, this code sets incomplete flag on records
loaded from pusher and loads the rest of the data only if needed.