1

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();
justinzane
  • 1,897
  • 1
  • 26
  • 38
  • http://stackoverflow.com/questions/4386701/extjs-restful-store-sending-request-in-batch?rq=1 seems to indicate that this does not work, however the answer is almost two years old. – justinzane Nov 16 '12 at 23:26

2 Answers2

0

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.

AndreKR
  • 32,613
  • 18
  • 106
  • 168
  • I saw that `batchActions` parameter. Could you explain how to actually setup batch requests. There is no obvious way to so something like `var myBatch = myProxy.createBatch(); myBatch.getByID('adsf'); .... myBatch.execute();` – justinzane Nov 17 '12 at 03:11
  • @justinzane try looking at the `batch()` method and the `batchOrder` property – CincauHangus Nov 20 '12 at 06:59
0

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.

CallMeLaNN
  • 8,328
  • 7
  • 59
  • 74