Dipish
19 Jun 2012, 1:12 AM
It used to be like that in Ext 3 but for some mysetrious reason this was changed in Ext 4.0 and remains in Ext 4.1.
So this is how Store.getById() (http://docs.sencha.com/ext-js/4-0/source/Store.html#Ext-data-Store-method-getById) currently looks like in 4.x:
getById: function(id) {
return (this.snapshot || this.data).findBy(function(record) { // OMG!
return record.getId() === id;
});
}
Where MixedCollection.findBy() (http://docs.sencha.com/ext-js/4-0/source/AbstractMixedCollection.html#Ext-util-AbstractMixedCollection-method-findBy) basically iterates through all the records sequentially calling the test function on each one. Obviously, the performance of this method potentially decreases with the number of records.
At the same time we have MixedCollection.getByKey() (http://docs.sencha.com/ext-js/4-0/source/AbstractMixedCollection.html#Ext-util-AbstractMixedCollection-method-getByKey) that looks like this:
getByKey : function(key) {
return this.map[key]; // that's what map is for!
}
Which gives us constantly fast seek time regardless of the number of records.
I was very surprised to see Store.getById() implementation change like that in 4.x, this kills all the benefits of having id index in the store!!! I do not expect the method to work like that.
PLEASE, explain why this has changed and correct me at any part where I'm wrong! Otherwise, please issue a fix ASAP.
So this is how Store.getById() (http://docs.sencha.com/ext-js/4-0/source/Store.html#Ext-data-Store-method-getById) currently looks like in 4.x:
getById: function(id) {
return (this.snapshot || this.data).findBy(function(record) { // OMG!
return record.getId() === id;
});
}
Where MixedCollection.findBy() (http://docs.sencha.com/ext-js/4-0/source/AbstractMixedCollection.html#Ext-util-AbstractMixedCollection-method-findBy) basically iterates through all the records sequentially calling the test function on each one. Obviously, the performance of this method potentially decreases with the number of records.
At the same time we have MixedCollection.getByKey() (http://docs.sencha.com/ext-js/4-0/source/AbstractMixedCollection.html#Ext-util-AbstractMixedCollection-method-getByKey) that looks like this:
getByKey : function(key) {
return this.map[key]; // that's what map is for!
}
Which gives us constantly fast seek time regardless of the number of records.
I was very surprised to see Store.getById() implementation change like that in 4.x, this kills all the benefits of having id index in the store!!! I do not expect the method to work like that.
PLEASE, explain why this has changed and correct me at any part where I'm wrong! Otherwise, please issue a fix ASAP.