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

BatchMaxQueries #1659

Merged
merged 17 commits into from Jun 20, 2017
Merged

BatchMaxQueries #1659

merged 17 commits into from Jun 20, 2017

Conversation

happylinks
Copy link
Contributor

@happylinks happylinks commented May 5, 2017

Issue reference: #1654

TODO:

  • If this PR is a new feature, reference an issue where a consensus about the design was reached (not necessary for small changes)
  • Make sure all of the significant new logic is covered by tests
  • Rebase your changes on master so that they can be merged easily
  • Make sure all tests and linter rules pass
  • Update CHANGELOG.md with your change
  • Add your name and email to the AUTHORS file (optional)
  • If this was a change that affects the external API, update the docs and post a link to the PR in the discussion

Docs: https://github.com/apollographql/core-docs/pull/302

@apollo-cla
Copy link

@happylinks: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Meteor Contributor Agreement here: https://contribute.meteor.com/

@happylinks
Copy link
Contributor Author

@helfer This is my first try. I'm having some issues with creating a correct test for this. Any hints would be great. I'll also keep trying myself of course.
After that I will add documentation, if you think this is the way to go.

Copy link
Contributor

@helfer helfer left a comment

Choose a reason for hiding this comment

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

Hey @happylinks, thanks for the PR! I think first you should fix the tests by removing the console.log statements. Then you can make the changes based on my comment, and then finally look at the current tests for the batch network interface and try to write a couple of tests that have a similar style and use the batchMax. One thing you could check is that if batchMax is 2 and you make 5 requests in a short interval (< batchInterval), you get 3 requests with 2, 2 and 1 query respectively.

@@ -62,20 +66,20 @@ export class QueryBatcher {
// Consumes the queue.
// Returns a list of promises (one for each query).
public consumeQueue(): (Promise<ExecutionResult> | undefined)[] | undefined {
const requests: Request[] = this.queuedRequests.map(
const queueSlice = this.queuedRequests.splice(0, this.batchMax);
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of slicing up when the queue is consumed, it would be better to immediately consume the queue once it reaches a length of batchMax. Otherwise you're still going to send all of those queries at the same time, just in chunks.

@happylinks
Copy link
Contributor Author

Sorry for the slow response. I actually got it working now, thanks for the hints. Do you think this test covers the full use-case or should I make more?
Also, should this be a breaking change, because if you don't have batchMax in your settings it will throw an error. This was also the case for batchInterval, but I'm not sure what the reasoning for that was. We could have a default maybe?

@happylinks happylinks changed the title WIP: BatchMaxQueries BatchMaxQueries Jun 1, 2017
@happylinks
Copy link
Contributor Author

happylinks commented Jun 12, 2017

Hi @helfer, I see you tried to merge master again but now the tests fail. Is there something I can do to help speed this PR up :)?

P.S. I'm also available to talk about this on the apollo slack.

Copy link
Contributor

@helfer helfer left a comment

Choose a reason for hiding this comment

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

Thanks @happylinks, I think the PR is almost ready to be merged, but we should make sure the new batchMax argument is optional. If it's not provided or set to 0, the behavior should be the same as before. Once the code is finished, you'll also have to make a PR to the docs so people can find out about it!


//This function is called to the queries in the queue to the server.
private batchFetchFunction: (request: Request[]) => Promise<ExecutionResult[]>;

constructor({
batchInterval,
batchMax,
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's make batchMax optional, and set it to 0 by default, in which case it should behave the same way it did before this PR.

test/batching.ts Outdated
@@ -16,6 +16,7 @@ describe('QueryBatcher', () => {
assert.doesNotThrow(() => {
const querySched = new QueryBatcher({
batchInterval: 10,
batchMax: 10,
Copy link
Contributor

Choose a reason for hiding this comment

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

If we make it optional, we won't have to add it to every test. This will also ensure that the change is not breaking for current users.

@@ -2201,6 +2204,109 @@ describe('client', () => {
});
});

it('should limit the amount of queries in a batch according to the batchMax value', (done) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This test looks good! After making batchMax optional, please also add a test that checks that no batching happens if batchMax is set to zero.

@happylinks
Copy link
Contributor Author

Hi @helfer, I made it optional. Also I changed the params of the HTTPBatchNetworkInterface to be an object. This made it nicer to have optional params. Let me know if that's ok.
I also made a PR for the documentation. Not sure if I should add it to more pages, but this seemed the best place.

@helfer
Copy link
Contributor

helfer commented Jun 20, 2017

It looks great now, thanks a lot @happylinks!

@helfer helfer merged commit 8b72ee2 into apollographql:master Jun 20, 2017
@happylinks
Copy link
Contributor Author

Awesome! Thanks for the help :)

@happylinks happylinks deleted the batchMax branch June 20, 2017 07:09
@jaydenseric
Copy link
Contributor

Just a heads up that the change in the constructor from parameters to an object is a breaking change for libraries like apollo-upload-client. After people update from v1.4.2 to v1.5.0, the error A remote endpoint is required for a network layer occurs. I'll quickly push out an update now.

I like the change to an object, it just would have been nice as a semver breaking change (apollo-client@2.0.0).

@helfer
Copy link
Contributor

helfer commented Jun 28, 2017

Hey @jaydenseric sorry about that!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants