-
21 Mar 2013 4:33 PM #1
Unanswered: store.getById too slow
Unanswered: store.getById too slow
Hi,
I need a faster search mechanism than iterating through all the records in the store by using store.getById(...).
I've looked at the code and tried to replace it with
but the records are not mapped using the Model configured 'idProperty', instead it's mapped using some auto-generated 'internalId' which is not something I can utilize.Code:Ext.override(Ext.data.Store, { getById: function (id) { return (this.snapshot || this.data).getByKey(id); } });
What can I do to search the store by id using a map?
Thanks,
Stevo
-
22 Mar 2013 10:47 AM #2Sencha - Support Team
- Join Date
- Jul 2010
- Location
- Houston, Tx
- Posts
- 7,190
- Vote Rating
- 195
- Answers
- 436
Is there no unique id field in the table?
Can you use a for/loop for all the records and perform your action instead of do a hard id search for each?
-
22 Mar 2013 11:23 AM #3
I have unique id's, which I'd love to use, but the store doesn't let me, there is no api for it
I need to find one specific record from the store by it's id (idProperty). I don't want to use for loop, that's expensive, I want to use (some kind of) map
-
30 Mar 2013 1:24 AM #4
How many records are in the store that you're using getById() on? I'm wondering why it's being slow for you. If you really want to map the records, you could do it when the store loads (or some other event happens). Here is sample code for writing a map and overriding the default getById function to use it:
Remember, you could always name the new method something other than getById.Code:Ext.define('App.override.Store', { override: 'Ext.data.Store', getById: function (id) { return this.idMap[id]; } }); var store = Ext.create('Ext.data.Store', { storeId: 'names', fields: ['id','Name'], data: [ { id: 1, Name: 'Bob' }, { id: 2, Name: 'Joe' }, { id: 3, Name: 'Watson' }, ] }); store.on('load', function(store, records, successful) { store.idMap = {}; if (successful) { Ext.Array.forEach(records, function(record) { store.idMap[record.getId()] = record; }); } });


Reply With Quote