Skip to content
This repository has been archived by the owner on Jul 4, 2021. It is now read-only.

Total records in infinite mode #257

Open
mir3z opened this issue Oct 1, 2014 · 7 comments
Open

Total records in infinite mode #257

mir3z opened this issue Oct 1, 2014 · 7 comments
Labels

Comments

@mir3z
Copy link

mir3z commented Oct 1, 2014

Consider following collection:

var Issues = Backbone.PageableCollection.extend({
        url: 'https://api.github.com/search/issues?q=repo:mozilla/BrowserQuest&sort=updated',
        model: Backbone.Model,
        mode: 'infinite',
        state: {
            pageSize: 9
        },
        queryParams: {
            totalPages: null,
            totalRecords: null
        },

        parseState: function (response) {
            return { totalRecords: response.total_count };
        },

        parseRecords: function (response) {
            return response.items;
        }
    });

After fetching this collection, state object will be:

{
    currentPage: 1,
    firstPage: 1,
    lastPage: 4,
    order: -1,
    pageSize: 9,
    sortKey: null,
    totalPages: 4,
    totalRecords: 35
}

This is incorrect since there are 26 issues returned by following request: https://api.github.com/search/issues?q=repo:mozilla/BrowserQuest&sort=updated&per_page=9&page=1

@wyuenho
Copy link
Member

wyuenho commented Mar 15, 2016

Not sure what's going on here. That's a query results different results as time goes by. Please ping me again when you have a confirmed case.

@ogonkov
Copy link
Collaborator

ogonkov commented Aug 7, 2018

@wyuenho I seems have similar issue. My server response with total records, but then it get incremented on each model add

if (!options.onRemove) {
++state.totalRecords;
delete options.onRemove;
}

Demo of the problem https://jsfiddle.net/ogonkov/vugfj02n/

While server responded with 5 records in collection and results_count (totalRecords) of 10, final state is 3 pages, and 15 records.

@ogonkov
Copy link
Collaborator

ogonkov commented Aug 7, 2018

This behaviour seems affects all versions since >=2.0.0 (haven't tested on 1.x)

@wyuenho
Copy link
Member

wyuenho commented Aug 8, 2018

There are so many things that could go wrong in your fiddle I can't figure out what's wrong. If you can simplify the fiddle to its bare essentials then I might be able to help.

@ogonkov
Copy link
Collaborator

ogonkov commented Aug 9, 2018

@wyuenho i have simplified example: removed mock stringifying, and log all state changes to console instead of DOM. Please have a look https://jsfiddle.net/ogonkov/vugfj02n/21/

@wyuenho wyuenho reopened this Aug 10, 2018
@wyuenho wyuenho added bug and removed invalid labels Aug 10, 2018
@hopkinschris
Copy link

@ogonkov Hey, were you ever able to resolve this issue?

@ogonkov
Copy link
Collaborator

ogonkov commented Sep 28, 2018

@hopkinschris not yet. I feel there should be some refactoring, to simplify thing that should happen during collection lifecycles. We need to know that totalRecords was changed during last sync, and take it into account, when we handle models add. We need to react to state change, in more smart way.

I have a kind of road map for this in my head:

  • move build to babel
  • convert whole code to es6 to simplify things; eliminate possible bugs
  • split code to modules, to make things more obvious, and get rid of this 150+ lines method, that hove line with the problem
  • don't break things ocassionally

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants