1
votes

I've got two model/proxy/stores I'm concerned with Questions and Choices. Both get data from a REST server as JSON. My process currently goes like this:

            // load numQuestions records from store.Questions
    var qs = Ext.getStore('Question');
            //... loadmask, etc.
    qs.load({
        scope : this,
        params : {
            limit : numQuestions
        },
        callback : function() {
            this.createQuestionCards(numQuestions);
        }
    });

Once I have the Questions, I loop through and fetch the Choices that are relevant to each Question like:

    for ( i = 0; i < numQuestions; i++) {
                // ... misc ...
        Assessor.questionChoices[i] = qs.getAt(i).choices();
                // ...misc...
        },

This works well, except that it makes an XMLHTTPRequest for every loop iteration. With minimum response times in the 0.15 sec area, that is fine for N < ~40. Once the numbers get to 200, which should be a common use case, the delay is nasty.

How do I get ExtJS to "batch" the requests and send them after the loop body? For example:

var choiceBatch = qs.createBatch();
for ( i = 0; i < numQuestions; i++) {
    // ... misc ...
    Assessor.questionChoices[i] = choiceBatch.getAt(i).choices();
    // ...misc...
};
choiceBatch.execute();
2
stackoverflow.com/questions/4386701/… seems to indicate that this does not work, however the answer is almost two years old.justinzane

2 Answers

0
votes

The Ext.data.proxy.Rest has a config option batchActions and since it's basically an AjaxProxy with different methods it will probably work in the same way as the AjaxProxy.

0
votes

Since I am not getting clear answer about restful batch with multipart...

testing on my own with batchActions=true in Ext.data.proxy.Rest v4.2.1 result that batch is only within the same store and HTTP method. (batchActions default to false for the REST)

That means if there is 200 post & 1 delete and you call store.sync(), it will batch into 2 request, the POST request body will be wrapped with an array of records instead of single record.

I am looking for if it can batch all stores with all GET, POST, PUT and DELETE by using multipart/mixed but the result is negative. (check out OData Batch Processing)

Regarding the OP, what you looking for is the model associations. Once you create Questions and Choices Ext model and let the server respond with nested json data (So the Questions contain the child Choices embedded in a request) Ext will create question record along with question.choices() child store automatically.