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
Improve the user experience of pagination. #5
Conversation
Collection results which require pagination now include "pages", "next_page" and "prev_page". The later two only if there are next or previous pages. For example: https://10.0.19.168/REST/2.0/queues/all?per_page=5\&page=3 { "count" : 5, "pages" : 8, "page" : 3, "per_page" : 5, "prev_page" : "https://10.0.19.168/REST/2.0/queues/all?per_page=5&page=2", "next_page" : "https://10.0.19.168/REST/2.0/queues/all?per_page=5&page=4", "total" : 37, "items" : [ ... ] }
Instead, use /correspond or /comment to add more contents.
This bug manifested with the behavior the comment notes this code is intended to prevent, namely that after a create, each custom field value is still updated, creating an additional transaction record.
$self->collection->RowsPerPage($per_page); | ||
|
||
my $max_page = ceil($self->collection->CountAll / $self->collection->RowsPerPage); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that at this point, any Limit passed in the request's JSON payload hasn't be applied yet. CountAll() will return the number of total (unlimited) records. So max_page is only an approximation here. The side effect is that CountAll() cache this (unlimited) value and next call to CountAll after the limit as been applied (in serialize) will still return the same (unlimited value). I'm not sure it's really useful to force the page passed in parameter not being greater than the max_page.
@@ -59,13 +65,37 @@ sub serialize { | |||
# TODO: Allow selection of desired fields | |||
push @results, expand_uid( $item->UID ); | |||
} | |||
return { | |||
|
|||
my %results = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since CountAll() has already been called in setup_paging before the collection has been limited, to avoid getting an outdated cache value a recount has to be forced with: $collection->{count_all} = 0;
or maybe avoid calling CountAll in setup_paging ?
Hello @puck! Thanks for this pull request, I hope it will me merged soon… Nevertheless I've stumbled on a bug caused by I've added some comment in the code of your pull request to fix this: either by forcing a recount before calling Here's a test that can be added at the end of
without the fix
|
Because we haven't applied the limits to the query yet, the call to CountAll returns the total number of results. Therefore, using that to limit the number of available of pages is useless.
Conflicts: Changes META.yml lib/RT/Extension/REST2.pm
Hey @gibus , thanks for that, given that CountAll will just result in a guesstimate, I've removed the flawed attempt to limit the number of pages. |
Conflicts: t/pagination.t
Conflicts: Changes lib/RT/Extension/REST2.pm
To simplify the merge request, remove this.
This pull request will be closed in favour of a new branch which doesn't have the copyright statement. |
Collection results which require pagination now include "pages",
"next_page" and "prev_page". The later two only if there are next
or previous pages. For example:
https://10.0.19.168/REST/2.0/queues/all?per_page=5\&page=3
{
"count" : 5,
"pages" : 8,
"page" : 3,
"per_page" : 5,
"prev_page" : "https://10.0.19.168/REST/2.0/queues/all?per_page=5&page=2",
"next_page" : "https://10.0.19.168/REST/2.0/queues/all?per_page=5&page=4",
"total" : 37,
"items" : [ ... ]
}