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

no Total-Records header in GET requests. only in HEAD requests. #1931

Merged

Conversation

peterbe
Copy link
Contributor

@peterbe peterbe commented Dec 10, 2018

Fixes #1624

  • Add documentation.
  • Add tests.
  • Add a changelog entry.
  • Add your name in the contributors file.
  • If you changed the HTTP API, update the API_VERSION constant and add an API changelog entry in the docs
  • If you added a new configuration setting, update the kinto.tpl file with it.
  • A bunch of storage tests use the now deprecated internal API of storage.get_all when in fact it should be using storage.list_all or storage.count_all.

@leplatrem
Copy link
Contributor

@peterbe, don't worry about the conflicts, I can do it and try to push a merge on your branch.

@leplatrem
Copy link
Contributor

I have one major question though: what do we do about our clients:

https://github.com/Kinto/kinto-http.js/blob/27737b9e62df2aff6adc32523708cd7e66131282/src/base.js#L540 --> Nan
https://github.com/Kinto/elm-kinto/blob/d5b5337166f23d130322858ace30c0a80abdca28/src/Kinto.elm#L299-L301 --> 0

Maybe we should first release of kinto-http.js where the totalRecords is obtained via a HEAD?
(I don't know, truely asking..)

@peterbe
Copy link
Contributor Author

peterbe commented Dec 10, 2018

Haven't dug in yet but the base.js you pointed to is inside a function called paginatedList and the doc string...

   * Fetch some pages from a paginated list, following the `next-page`
   * header automatically until we have fetched the requested number
   * of pages. Return a response with a `.next()` method that can be
   * called to fetch more results.

So, if the idea is that you use...

for (const page in client.paginatedList(args)) {
  ...
}

...then we're fairly certain the total records is not needed or used. The pagination is done using Next-Page.

Perhaps my brain is a bit end-of-day fried and there's a lot of mind-bending async in that code but it looks like the totalRecords isn't actually used.

@glasserc
Copy link
Contributor

Yeah, my hypothesis is that nobody actually uses the totalRecords field on the paginatedList result, but just pages the results. I think automatically including a call to getTotalRecords (on each page...) would be a prohibitive performance penalty and would rather not do that.

Copy link
Contributor

@leplatrem leplatrem left a comment

Choose a reason for hiding this comment

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

Appart from the count_only in the model get_objects(), it looks good to me!

GG! 🙌

Also, this is not a minor change from the client perspective. The totalRecords is exposed in the result of listRecords() in kinto-http.js for example. I think we should be very explicit about the change in the API changelog. If we say we follow semver, we should bump a major for the API version, and well....I'm not sure we're ready for that. So, at least we should be very explicit!

@@ -1,6 +1,3 @@
A ``Total-Objects`` response header indicates the total number of objects
of the list (not the response, since it can be paginated).
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably have a _details-head-list.rst where we mention that the header can be obtained with HEAD

kinto/core/resource/__init__.py Show resolved Hide resolved
docs/api/1.x/selecting_fields.rst Outdated Show resolved Hide resolved
docs/api/1.x/records.rst Outdated Show resolved Hide resolved
Copy link
Contributor

@glasserc glasserc left a comment

Choose a reason for hiding this comment

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

At a glance it looks OK. I'll defer to Mat for review on this. This PR badly needs a rebase :)

@peterbe
Copy link
Contributor Author

peterbe commented Dec 11, 2018

This PR badly needs a rebase

Do you mean a squash? Isn't that done with the green button when it's fully approved?

Or do you mean it needs the latest and greatest of master?

It's hard to remember what different projects have as best practices with active PRs and the landing protocol.

@Natim
Copy link
Member

Natim commented Dec 11, 2018

Usually in the Kinto org we merge without squashing to keep the history and pace of the pull-request. Here we just need to fix tests I guess

@peterbe
Copy link
Contributor Author

peterbe commented Dec 11, 2018

I can rebase this to get rid of unimportant small commits but keep stuff like the master merge and various others. But I don't think we're done yet :)

@Natim
Copy link
Member

Natim commented Dec 11, 2018

No don't worry about that.

@glasserc
Copy link
Contributor

Do you mean a squash?

No, I meant a rebase, meaning moving these comments onto master so that we get fewer wacky diffs like this:

screenshot from 2018-12-11 21-29-27
screenshot from 2018-12-11 21-29-48

@leplatrem
Copy link
Contributor

The wacky diffs come from some mistakes I made during the painful merge I guess.

@leplatrem
Copy link
Contributor

leplatrem commented Dec 12, 2018

@peterbe, I merged and repaired the merge :) Tests now pass.

I believe what remains is:

  • be extremely clear about the removal of the header in GET in changelog
  • Maybe we could have a server setting to maintain the header if set to True (default: false) for situations where clients rely on this info
  • document that the header can be obtained with HEAD
  • figure out a way to nicely document that we Total-Records is now deprecated in favor of Total-Objects because of Rename core notions #710
  • improve the models code (eg. two methods instead of count_only param)
  • squash could be a good idea (didn't want to force push on your branch ;))
  • kinto/core/storage/testing.py still uses objects, total_count = self.storage.get_all(params) and that causes deprecation warnings.

@peterbe
Copy link
Contributor Author

peterbe commented Dec 13, 2018

@leplatrem It's a bit of a mess but check out the latest couple of commits related to documentation and whether it solves the figure out a way to nicely document that we Total-Records is now deprecated in favor of Total-Objects because of checkbox above.

Also, see the latest commit regarding how I broken up model.get_objects so we no longer need this count_only=boolean stuff.

Copy link
Contributor

@leplatrem leplatrem left a comment

Choose a reason for hiding this comment

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

Niiice!

Thanks for the hard work!

I made a few comment, the main one is about having a deprecation decorator for a method that was just introduced! Otherwise, it looks like close to the finish line :)

docs/api/1.x/records.rst Outdated Show resolved Hide resolved
docs/api/1.x/records.rst Show resolved Hide resolved
kinto/core/storage/memory.py Outdated Show resolved Hide resolved
kinto/core/storage/testing.py Show resolved Hide resolved
tests/test_views_permissions.py Show resolved Hide resolved
kinto/core/storage/__init__.py Show resolved Hide resolved
Copy link
Contributor

@glasserc glasserc left a comment

Choose a reason for hiding this comment

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

Just some drive-by comments..

CHANGELOG.rst Show resolved Hide resolved
docs/api/1.x/history.rst Outdated Show resolved Hide resolved
Copy link
Contributor

@leplatrem leplatrem left a comment

Choose a reason for hiding this comment

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

🎉 🎉

I let you rebase/squash/do whatever you want before pressing the merge button ;)

@@ -0,0 +1,10 @@
Unlike GET requests, HEAD requests contain an additional header called ``Total-Objects``
(and ``Total-Records`` for backwards compatibility) which is a count of all objects
in the collection with the current filtering.
Copy link
Contributor

Choose a reason for hiding this comment

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

in the resource?

@peterbe
Copy link
Contributor Author

peterbe commented Dec 17, 2018

I let you rebase/squash/do whatever you want before pressing the merge button

I don't think there are any commits that are worthy to have to be squashed. If I do try to selectively squash some of them, I will have to go through the same merge conflicts you went through, no?

@leplatrem
Copy link
Contributor

Yeah, I'm ok with whatever ;)

@peterbe peterbe merged commit 31f72b1 into Kinto:master Dec 18, 2018
@peterbe peterbe deleted the 1624-what-should-we-do-with-total-records branch December 18, 2018 14:11
glasserc added a commit to Kinto/kinto-http.js that referenced this pull request Dec 31, 2018
This got removed in Kinto/kinto#1931, and has
been causing failing tests ever since.
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