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

Auto pagination #596

Merged
merged 15 commits into from
Aug 6, 2018
Merged

Auto pagination #596

merged 15 commits into from
Aug 6, 2018

Conversation

aoberoi
Copy link
Contributor

@aoberoi aoberoi commented Jul 25, 2018

Summary

The platform is expanding the set of methods which support the shiniest of our pagination specifications, cursor-based pagination!

This change allows apps who previously made API calls to methods (that support cursor pagination) without any explicit pagination arguments to transparently traverse pages. This solves two major problems:

  1. Previously, if the list was too long to return in a reasonable amount of time, these requests may result in server errors (500 response code).
  2. Some methods started to return partial lists (with default limit values) in situations where the client didn't provide pagination arguments. This would create a subtle bug, but now these apps should get the entire list.

This change also helps apps prepare for a future where pagination becomes mandatory in certain situations.

Fixes #343

Please review and provide feedback

At this point, my biggest concern is that this is a lot of new code, for what amounts to functionality we still strongly recommend developers do not use. More specifically, we still want developers to paginate requests themselves, and not to depend on the automatic pagination. Our reason is that this will result in more performant and optimized code. So, planting all this code is very intentionally a band-aid. My proposal for how we'd address this concern is to merge this now, and in the next major version to remove automatic pagination; moving that code into an add-on that can be used in conjunction with the baseline package. That add-on would be a shim that's only for backwards compatibility, but not encouraged.

Another concern is now the cursorPaginationEnabledMethods in methods.ts value is starting to store metadata about API responses, but outside of the holistic design we're hoping to arrive in #496 and #509.

TODO

  • Sync metadata with the latest round of cursor-pagination supporting methods
  • Implement tests and get acceptable coverage
  • Add configuration for rate-limit retires (simple boolean) make webclient rate-limit retries configurable #451 This can be done in a separate, follow-up PR, which will make it easier to review.
  • Handle general httpError conditions (like 500 responses)
  • Audit error types and codes
  • Turn default page size into a configuration option
  • Document the new feature(s)

Requirements (place an x in each [ ])

@codecov
Copy link

codecov bot commented Jul 25, 2018

Codecov Report

Merging #596 into master will increase coverage by 1.43%.
The diff coverage is 91.25%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #596      +/-   ##
==========================================
+ Coverage   86.83%   88.26%   +1.43%     
==========================================
  Files           6        7       +1     
  Lines         281      409     +128     
  Branches       44       70      +26     
==========================================
+ Hits          244      361     +117     
- Misses         26       31       +5     
- Partials       11       17       +6
Impacted Files Coverage Δ
src/IncomingWebhook.ts 65.71% <ø> (ø) ⬆️
src/retry-policies.ts 100% <ø> (ø) ⬆️
src/methods.ts 100% <100%> (ø)
src/util.ts 73.33% <100%> (+5.76%) ⬆️
src/logger.ts 89.74% <100%> (+1.86%) ⬆️
src/WebClient.ts 91.26% <87.38%> (-2.66%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f51bdda...e28cc36. Read the comment docs.

"url-join": "^4.0.0",
"ws": "^5.2.0"
},
"devDependencies": {
"@aoberoi/capture-console": "^1.0.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

😎

src/logger.ts Outdated
@@ -79,7 +81,13 @@ log.methodFactory = function (
* INTERNAL interface for getting or creating a named Logger
*/
// TODO: implement logger name prefixing (example plugins available on the loglevel package's site)
export const getLogger = log.getLogger as (name: string) => Logger;
// export const getLogger = log.getLogger as (name: string) => Logger;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be deleted?

export async function awaitAndReduce<T, U>(iterable: AsyncIterable<T>,
callbackfn: (previousValue: U, currentValue: T) => U,
initialValue: U): Promise<U> {
// TODO: make initialValue optional (overloads or conditional types?)
Copy link
Contributor

Choose a reason for hiding this comment

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

🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

meh, i think i'll leave that comment in there.

right now we don't need a version of this function that doesn't take an initialValue because i'm manually passing {} as WebAPICallResult into it. but, since this lives in util.ts, it would be more reusable if it didn't need an initial value, the way that Array.prototype.reduce also doesn't require an initial value.

@aoberoi aoberoi merged commit fec7950 into slackapi:master Aug 6, 2018
@aoberoi aoberoi deleted the auto-pagination branch August 6, 2018 18:16
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.

2 participants