vendredi 16 octobre 2015

Why is store.query() so slow?

I have to load a fairly big collection (13 - 15k records). I can't change the api, so I have to deal with it. I noticed a performance difference between using (1) store.query() and (2) doing a manual ajax-request + populate the store via store.createRecord().

The network request takes ~6 seconds. The store.query promise resolves after ~ 10 seconds. So I guess the ~4 seconds are internally spent in resolving the adapter and serializer, populating the store and returning the data from it.

But when I populate the store manually it takes just 1-2 seconds. Here's the approach:

icAjaxRaw({
  ...
})
.then((res) => {
  let assets = res.response.data;
  console.log('data requested', moment().format());
  _.each(assets, function(asset) {
    this.store.createRecord('asset', asset);
  }, this);
  console.log('before store peekAll', moment().format());
  return this.store.peekAll('asset');
});

What's causing store.query to be so much slower?

Note: My adapter only overrides the url (via urlForQuery()) and my serializer only extracts the data-property from the payload. So that can't be the culprit.




Aucun commentaire:

Enregistrer un commentaire