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

Prefer Flux#take(long, boolean) over Flux#take(long) to limit upstream generation #314

Merged
merged 4 commits into from
Oct 26, 2022

Conversation

eric-picnic
Copy link
Contributor

In Reactor versions prior to 3.5.0, Flux#take(n) makes an unbounded request upstream, and is equivalent to Flux#take(n, false). In 3.5.0, the behavior of Flux#take(n) will change to that of Flux#take(n, true).

The intent with this Refaster rule is to get the new behavior before upgrading to Reactor 3.5.0.

@eric-picnic eric-picnic requested review from werli and rickie October 25, 2022 10:46
@eric-picnic
Copy link
Contributor Author

eric-picnic commented Oct 25, 2022

Suggested commit message:

Prefer `Flux#take(long, boolean)` over `Flux#take(long)` to limit upstream generation (#314)

@rickie rickie added this to the 0.5.0 milestone Oct 25, 2022
Copy link
Member

@rickie rickie left a comment

Choose a reason for hiding this comment

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

Added a commit.

Have some suggestions, but overall, looks really good!

Congrats on your first Error Prone Support contribution 🎉 !

W.r.t. the suggested commit message, need to think about it 👀.


@AfterTemplate
Flux<T> after(Flux<T> flux, long n) {
return flux.take(n, /* limitRequest= */ true);
Copy link
Member

Choose a reason for hiding this comment

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

Gotta love the self-check profile, didn't expect this to show up in the after-template.

Fun fact; if we really want to add this comment in the actual output of applying a Refaster rule, we can use Refaster#emitComment or Refaster#emitCommentBefore.

Copy link
Member

Choose a reason for hiding this comment

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

Yep! We don't have BooleanParameter enabled internally, so I think it's fine as-is 👍

@@ -144,6 +144,18 @@ Mono<S> after(Mono<T> mono, S object) {
}
}

static final class FluxTakeGenerationLimit<T> {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
static final class FluxTakeGenerationLimit<T> {
static final class FluxTake<T> {

Copy link
Member

Choose a reason for hiding this comment

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

We use content of the after-template to determine how we should name the Refaster rule. We can simply write FluxTake here as we see in the after-template.

(We are working on a naming algorithm that will be enforced.)

@@ -144,6 +144,18 @@ Mono<S> after(Mono<T> mono, S object) {
}
}

static final class FluxTakeGenerationLimit<T> {
Copy link
Member

Choose a reason for hiding this comment

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

Let's add a Javadoc here as well :).

@rickie rickie requested a review from Stephan202 October 25, 2022 12:08
@rickie
Copy link
Member

rickie commented Oct 25, 2022

I'm thinking about the suggested commit message. I think it'd be better to add that information to the Javadoc as this information is good to have in the project. Otherwise it would get "lost" in the git history. So I'd go for moving it to there and simplify the suggested commit message. WDYT @eric-picnic ?

@eric-picnic
Copy link
Contributor Author

I think it'd be better to add that information to the Javadoc as this information is good to have in the project.

I agree. I have moved it from the suggested commit message to the Javadoc of FluxTake.

eric-picnic and others added 3 commits October 25, 2022 17:51
In Reactor versions prior to 3.5.0, `Flux#take(n)` makes an unbounded
request upstream, and is equivalent to `Flux#take(n, false)`.
In 3.5.0, the behavior of `Flux#take(n)` will change to that of
`Flux#take(n, true)`.

The intent with this Refaster rule is to get the new behavior
before upgrading to Reactor 3.5.0.
Copy link
Member

@werli werli left a comment

Choose a reason for hiding this comment

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

Nice! Sweet to see this suggestion I had made quite some time ago make it to EPS! 🚀

Sweet work @eric-picnic 💪 Congrats on the first contribution here.

@Stephan202 Stephan202 force-pushed the eric-picnic/limit-flux-take branch from 3eacc3b to 46ab26b Compare October 25, 2022 16:57
Copy link
Member

@Stephan202 Stephan202 left a comment

Choose a reason for hiding this comment

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

Rebased and added a commit. Very nice!

I tweaked the suggested commit message, but feel free to revert.


@AfterTemplate
Flux<T> after(Flux<T> flux, long n) {
return flux.take(n, /* limitRequest= */ true);
Copy link
Member

Choose a reason for hiding this comment

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

Yep! We don't have BooleanParameter enabled internally, so I think it's fine as-is 👍

/**
* Prefer {@link Flux#take(long, boolean)} over {@link Flux#take(long)}.
*
* <p>In Reactor versions prior to 3.5.0, `Flux#take(long)` makes an unbounded request upstream,
Copy link
Member

Choose a reason for hiding this comment

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

Since it's Javadoc we generally use {@code instead of backticks.

Comment on lines +154 to +158
* <p>The intent with this Refaster rule is to get the new behavior before upgrading to Reactor
* 3.5.0.
Copy link
Member

Choose a reason for hiding this comment

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

Once on 3.6.0 we'll want to simplify the code in the opposite direction 😄. I'll add a comment.

* <p>The intent with this Refaster rule is to get the new behavior before upgrading to Reactor
* 3.5.0.
*/
static final class FluxTake<T> {
Copy link
Member

Choose a reason for hiding this comment

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

This is one of the few (perhaps the first?) Refaster rules that is intentionally not behavior preserving. A good opportunity to use the @Description and @Severity annotations introduced in #255. 😄

@rickie rickie changed the title Prefer Flux#take(n, true) over Flux#take(n) to limit generation Prefer Flux#take(long, boolean) over Flux#take(long) to limit upstream generation Oct 26, 2022
@rickie rickie merged commit 45dfc53 into master Oct 26, 2022
@rickie rickie deleted the eric-picnic/limit-flux-take branch October 26, 2022 06:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

4 participants