lundi 1 juin 2015

How can I unload unused records from Ember Data Store?

I'm having a memory concern. I have found this but I don't want to delete old records, I want to delete ones that are not used.

For now, I have created this:

limitRecordsAmount: 50,
domain: 'product',

allRecords: function(){
  return this.store.all(this.get('domain'));
}.property('domain'),

recordsCount: Em.computed.alias('allRecords.length'),
watchSize: function(){
  var count = this.get('messageCount'),
      limit = this.get('limitRecordsAmount'),
      records;
  if( count > limit ){
     records = this.get('allRecords').sortBy('lastUse').toArray().slice(limit);
     records.forEach(function(record){
       record.unloadRecord();
     });
  }
}.observes('recordsCount', 'limitRecordsAmount')

I only need to assign lastUse, but I'm not sure how to do that. Should I do it in the store when a record is accessed? And if so, where should I put it? I was thinking about getById and findQuery.




Aucun commentaire:

Enregistrer un commentaire