Results 1 to 7 of 7

Thread: Buffered store ALWAYS send two requests on load, event if all data fetched

  1. #1
    Sencha User
    Join Date
    Oct 2013
    Posts
    55
    Answers
    1

    Default Buffered store ALWAYS send two requests on load, event if all data fetched

    Hi, could somebody make this behavior clear for me?

    I am using ExtJS 6.2.0
    I have a database table with 3000 rows.
    I have a buffered store with pageSize set to 5000.
    Grid can display 30 rows in visible area.

    When I run store.reload() it ALWAYS sends two requests:

    first request: start = 0, limit = 5000;
    server response: total: 3000 and return all 3000 rows.

    Then, store perform second request:

    second request: start = 5000, limit = 5000;
    server response: total: 3000 and return 0 rows - this is obvious.

    I don't understand, why the second request is issued, If in the first request we are clearly understand, that all data is already fetched?
    Is this is a bug?

    UPDATE
    I found, that two requests are issued ONLY if I use store.reload() method.
    But if I call store.load() - it works, as it should, and issue only single request.

  2. #2
    Sencha MVP Team Member
    Join Date
    Sep 2016
    Location
    Kennewick, WA
    Posts
    150
    Answers
    15

    Default

    Per documentation it appears loading twice is expected when using
    store.reload()
    .

  3. #3
    Sencha User
    Join Date
    Oct 2013
    Posts
    55
    Answers
    1

    Default

    Thank you for reply.
    I read docs for reload() method once more and didn't find any mention about that it can issue two requests.

  4. #4
    Sencha MVP Team Member
    Join Date
    Sep 2016
    Location
    Kennewick, WA
    Posts
    150
    Answers
    15

    Default

    I've read them again and could have misunderstood their documentation. I took the impression it was sending twice. Do you have a fiddle of the code or can you post code, just to see what else is happening to better help answer the question?

  5. #5
    Sencha User
    Join Date
    Oct 2013
    Posts
    55
    Answers
    1

    Default

    I didn't created fiddle.
    I don't know how to create store, that will use api to load remote data, this task i too complex for fiddle.

  6. #6
    Sencha Premium Member
    Join Date
    Mar 2016
    Posts
    3

    Default reload store will not send two request

    The reload code is just call load function so this is not the reason to send two requests.

    reload: function(options) {
    return this.load(Ext.apply({}, options, this.lastOptions));
    },

  7. #7
    Sencha User
    Join Date
    Oct 2009
    Posts
    67
    Answers
    2

    Default

    Code:
    Ext.data.BufferedStore.override({
        reload: function (options) {
            var me = this,
                data = me.getData(),
                // If we don't have a known totalCount, use a huge value
                lastTotal = Number.MAX_VALUE,
                startIdx, endIdx, startPage, endPage,
                i, waitForReload, bufferZone, records;
    
    
            if (!options) {
                options = {};
            }
    
    
            // FIX *** Total count property defined
            if (me.totalCountDefined) {
                lastTotal = me.getTotalCount();
            }
    
    
            // Prevent re-entering the load process if we are already in a wait state for a batch of pages.
            if (me.loading || me.fireEvent('beforeload', me, options) === false) {
                return;
            }
    
    
            waitForReload = function() {
                var newCount = me.totalCount,
                    oldRequestSize = endIdx - startIdx;
    
    
                // If the dataset has now shrunk leaving the calculated request zone unavailable,
                // re-evaluate the request zone. Start as close to the end as possible.
                if (endIdx >= newCount) {
                    endIdx = newCount - 1;
                    startIdx = Math.max(endIdx - oldRequestSize, 0);
                }
                if (me.rangeCached(startIdx, endIdx, false)) {
                    me.loadCount = (me.loadCount || 0) + 1;
                    me.loading = false;
                    data.un('pageadd', waitForReload);
                    records = data.getRange(startIdx, endIdx);
                    me.fireEvent('refresh', me);
                    me.fireEvent('load', me, records, true);
                }
            };
            bufferZone = Math.ceil((me.getLeadingBufferZone() + me.getTrailingBufferZone()) / 2);
    
    
            // Decide what reload means.
            // If the View was configured preserveScrollOnReload, then it will
            // inject that setting here. This means that reload means
            // load the last requested range.
            if (me.lastRequestStart && me.preserveScrollOnReload) {
                startIdx = me.lastRequestStart;
                endIdx = me.lastRequestEnd;
                lastTotal = me.getTotalCount();
            }
            // Otherwise, reload means start from page 1
            else {
    
    
                startIdx = options.start || 0;
                endIdx = startIdx + (options.count || me.getPageSize()) - 1;
            }
    
    
            // Clear page cache
            data.clear(true);
    
    
            // So that prefetchPage does not consider the store to be fully loaded if the local count is equal to the total count
            delete me.totalCount;
    
    
            // Calculate a page range which encompasses the Store's loaded range plus both buffer zones
            startIdx = Math.max(startIdx - bufferZone, 0);
            endIdx = Math.min(endIdx + bufferZone, lastTotal);
    
    
            // We must wait for a slightly wider range to be cached.
            // This is to allow grouping features to peek at the two surrounding records
            // when rendering a *range* of records to see whether the start of the range
            // really is a group start and the end of the range really is a group end.
            startIdx = startIdx === 0 ? 0 : startIdx - 1;
            endIdx = endIdx === lastTotal ? endIdx : endIdx + 1;
    
    
            startPage = me.getPageFromRecordIndex(startIdx);
            endPage = me.getPageFromRecordIndex(endIdx);
    
    
            me.loading = true;
            options.waitForReload = waitForReload;
    
    
            // Wait for the requested range to become available in the page map
            // Load the range as soon as the whole range is available
            data.on('pageadd', waitForReload);
    
    
            // Recache the page range which encapsulates our visible records
            for (i = startPage; i <= endPage; i++) {
                me.prefetchPage(i, options);
            }
        }
    });
    Store config:

    Code:
    {
         type: 'buffered',
         totalCountDefined: true
    }

Similar Threads

  1. [OPEN] Buffered store load event not firing ExtJS 6.0, 5.1.0 and 5.0
    By suzuki1100nz in forum Ext JS 6.x Bugs
    Replies: 5
    Last Post: 20 Jun 2016, 1:22 AM
  2. Replies: 1
    Last Post: 1 Apr 2015, 1:41 PM
  3. Replies: 1
    Last Post: 6 Jan 2014, 6:43 AM
  4. Replies: 1
    Last Post: 12 Sep 2012, 10:48 AM
  5. Replies: 3
    Last Post: 13 Feb 2012, 4:46 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •