-
-
Notifications
You must be signed in to change notification settings - Fork 72
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
Implement Batching #99
Conversation
@tisto this one is ready for review |
f9d2bcc
to
1541bcd
Compare
@buchi fixed some flaky tests and rebased onto master - please review |
4a7630a
to
7585eb7
Compare
@buchi updated to not have |
Still need some time for the review. Will do asap. @lukasgraf PR needs rebase |
@buchi rebased |
content-type: application/json | ||
|
||
{ | ||
"@id": "http://localhost:55001/plone/folder/@search?sort_on=path", |
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.
@lukasgraf if the request is on "/folder/@search?b_size=5&sort_on=path", why is the @id equals "/folder/@search?sort_on=path" (without the "b_size")? Shouldn't this be either the base request or the full request with all params?
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.
@tisto no, this is supposed to be the canonical ID to the base collection without any batching information (loosely based on https://www.w3.org/community/hydra/wiki/Collection_Design#Pagination / https://www.w3.org/community/hydra/wiki/Pagination#PartialCollection). The ID for the current batch is in batching/@id
.
I guess the sort_on
parameter doesn't really affect the collection's contents, just their ordering. But if you consider other query string parameters for @search
(or possibly other endpoints), the query string params can directly affect what resource will be returned, so I'm preserving them and just stripping batching related params for the canonical resource URL.
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.
Right. My feeling is that we should remove the sort_on param from the canonical top-level id as well. Do we have any hypermedia controls for changing the sort order? Have you looked into that?
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.
@tisto I briefly looked into it, but couldn't find any spec for hypermedia controls to specify sort order that are standarized in any sense. Updated HypermediaBatch.canonical_url
to also remove sorting related params.
Maybe we should rather call it pagination or paging. Batching is often used in the context of performing bulk operations. Any thoughts? |
What about including |
"next": "http://.../plone/folder/search?b_size=10&b_start=30" | ||
}, | ||
"total_items": 175, | ||
"member": [ |
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.
has been renamed to items
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.
Ah, well spotted. I will do one more pass for member
-> items
.
The term "pagination" is definitely much more common outside the Plone world. Since we're doing a rather low-level API that exposes many of the implementation details already I decided to stick with Plone's naming. I wouldn't be opposed to naming it "pagination", but calling it that and still using the |
Re: moving |
@buch @lukasgraf the rationale behind the top-level total_items is that all items inside "batching" are supposed to be hypermedia controls that the client just exposes 1:1 to the user. If we start adding more items there we will end up with tight coupling between client and server because the client needs to know about the exact structure and names of the API. |
@tisto I see - we'll leave it like that then. The client shouldn't be relying on |
@@ -19,5 +25,5 @@ content-type: application/json | |||
"title": "Test Folder" | |||
} | |||
], | |||
"items_count": 2 | |||
"total_items": 2 |
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.
@lukasgraf I'm wondering if it would make sense to rename "total_items" to "items_total". This would make "items_total" show up right after "items". Does not make any difference for the consumer app but for a developer browsing the API.
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.
We could, I don't have any strong feelings about either one ;) Regarding developer-friendly representations though, we might want to look into using OrderedDict
s at some point. If given an ordered dict, json.dumps()
will preserve the order of the keys. Structurally the order of keys in a dict still has no meaning of course, but that might make it easier to produce JSON that is layed out in a human-friendly way.
Right now the batching information is included even when the items count doesn't exceed the batch size. |
@buchi sounds good to me. Though if we were to still include the |
Can we get a consensus on renaming |
@lukasgraf +1 |
The LazyCatalogResultSerializer has been removed in #99 without a pressing need to do so. Therefore we re-introduce it here and make it handle the batching logic that was previously left to the SearchHandler.
Implements batching for
Also changes implementation for
GET
on folderish contexts so catalog queries are used instead ofobjectValues()
.TODO:
25
in most places, so I changed the default inplone.restapi.batching
to that as well)items_count
tototal_items
Closes #8