Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New pagination #162

Closed
wants to merge 19 commits into from
Closed

New pagination #162

wants to merge 19 commits into from

Conversation

garrensmith
Copy link
Member

This is an improvement and fix on the current pagination. Currently the pagination doesn't work correctly when using startkey, endkey or any of the other query options. It also shows an incorrect value for how many documents are in the view query.

This patch is very large because pagination in Couchdb is quite complex and there are plenty of situations to cater for. This new pagination works quite differently to the previous way we had it working for a user.

A user can set the number of documents they want to view on a page. This is not related to limit options in the query options - the limit option is an overall cap of how many documents to paginate too. A limit of none is possible and is the default. If the limit option is set to 50 and a user wants 10 docs per page, the would then be able to paginate 3 pages before hitting the end.

Another change is that the api url and browser url does not change when we paginate. That happens internally and hence the new addition of urlParams and docParams. This allows Fauxton to keep track of the parameters that the user sees and the parameters that the document needs to paginate.

The majority of this work is finding the right way to paginate given a variety of query options. This is quite tricky and we had to build up scenarios of different query options and then how to paginate with them.

this.params = options.params;
this.skipFirstItem = false;

this.params = _.clone(options.params);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clone is neat. Why chose this over duplicating the options.params?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite follow you here, _.clone is basically a duplicate?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NM, I googled. Garren, I can't write proper questions. Sorry

@kxepal
Copy link
Member

kxepal commented Mar 3, 2014

Looks as a lot of work! But could you provide some summary what have changed, what does it improved and...why?(:

@kxepal
Copy link
Member

kxepal commented Mar 3, 2014

Bug: Page sizes 50 and 100 for browsing views doesn't works. Actually, it applies last selected page size or 20.

// this is really ugly. But we basically need to make sure that
// all parameters are in the correct state and have been parsed before we
// calculate how to paginate the collection
_.each(['startkey', 'endkey', 'key'], function (key) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you pull this out into it's own function?

@kxepal
Copy link
Member

kxepal commented Mar 3, 2014

Another moment: when paginates views, Fauxton adds limit=N argument to the URL. It's awesome! But if I set N as 11, 15, 42, 100500, Fauxton accepts the specified value, but doesn't reflect it in Per page select box.

@kxepal
Copy link
Member

kxepal commented Mar 3, 2014

Also, if I set bad value for limit in URL like limit=foo, Fauxton will show Bad request error popup and resets limit to 100 while default value is 20.

@@ -27,10 +27,14 @@ function require(path, parent, orig) {
// perform real require()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heh did you update chai too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was adding tests and realised we needed latest chai. This is stupid to update chai.js while working on a patch. So sorry about that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha it's fine. I was just like "wow lotta files changed for pagination"

@kxepal
Copy link
Member

kxepal commented Mar 3, 2014

Bug: Page sizes 50 and 100 for browsing views doesn't works. Actually, it applies last selected page size or 20.

More notes: it only raises if limit=N is in URL. By default it's missed, but just navigate to some document and click on "Back to _all_docs" or enter it manually.

@kxepal
Copy link
Member

kxepal commented Mar 3, 2014

@deathbearbrown hm?

@deathbearbrown
Copy link
Member

I think we want to move away from passing the limit parameters in the route fragment.

@kxepal
Copy link
Member

kxepal commented Mar 3, 2014

@deathbearbrown if so, then Fauxton shouldn't process them. However, I see that you wanted to kill the feature: processing query params from route url allows users to exchange views requests via URL and without talks like: "open view X, click query options, set startkey=Y, endkey=Z, limit=Q, reduce=false and you'll see the result as I do"

@kxepal
Copy link
Member

kxepal commented Mar 3, 2014

or another case: you configured query for specific view in Fauxton and know wanted to make the same request via curl or whatever client. Just copypaste the URL and remove /_utils/fauxton substring is better than typing all view query options manually again.

@deathbearbrown
Copy link
Member

Ack I keep accidentally posting half your name.

The API URL button is what is going to show the URL for you to do curl commands, not the fauxton url.

@garrensmith
Copy link
Member Author

@kxepal Can you explain what you mean by the 50 and 100 limits not working?

@kxepal
Copy link
Member

kxepal commented Mar 4, 2014

@garrensmith get it 100% reproduce:

  • Navigate to any view
  • Open Query Options
  • Set Limit to lets say 20
  • Query the view
  • Collapse Query Options
  • Try to set page size 5 - ok
  • Try to set page size 20 - ok
  • Try to set page size 30 - it's still will be 20
  • Try to set page size 50 - again
  • Try to set page size 100 - and again
  • Going back to page size 10 - everything is fine

Sorry, no video: just found that gtk-recordMyDesktop generates broken picture.

@kxepal
Copy link
Member

kxepal commented Mar 4, 2014

@deathbearbrown

The API URL button is what is going to show the URL for you to do curl commands, not the fauxton url.

Yes, and I was talking about sharing URL with Fauxton with all setted view query parameters. Different things.

@asfbot
Copy link

asfbot commented Mar 4, 2014

Simon Metson on [email protected], [email protected] replies:
That sounds like the correct behaviour. You've constrained the result set to 20 docs, so a page size >20 isn't going to show more docs. The same would happen if the DB only had 20 docs in.

@kxepal
Copy link
Member

kxepal commented Mar 4, 2014

Simon:

I and @garrensmith just discussed this topic in IRC. TL;DR this is could be correct behaviour for Fauxton, but 1) it's not oblivious 2) 90% users will come to Fauxton with Futon experience and such behaviour is completely unexpected for them and could be only recognized as a bug.

If so and it's expected, Fauxton shouldn't provide options to select that doesn't works and it should explicitly declare "why functionality which I have used two minutes ago is missed". If you take a look on screen, you'll didn't notice any page size cap. Only 1) if you open Query Options, but it consumes a lot of visible space to keep it always opened 2) if you take a look on URL, but there could be a lot of parameters and @deathbearbrown going to get rid them from there.

So, whatever the behavior is, there are some problems with it.

@asfbot
Copy link

asfbot commented Mar 4, 2014

Simon Metson on [email protected], [email protected] replies:
I think the right thing to do is have some kind of "expecting more docs? Check your " message if the number of docs is less than the page size, and advanced options are set.

The alternative is removing the limit option, which doesn't solve the problem for other limiting options, or having conditional messaging around the page size.

@deathbearbrown
Copy link
Member

Testing this now and nothing is breaking for me. +1?

@asfgit asfgit deleted the paginate-api-options branch July 26, 2016 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants