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

This avoids a CF allocation on data fetcher in the main case where there is no exception #3235

Merged
merged 1 commit into from Jun 7, 2023

Conversation

bbakerman
Copy link
Member

No description provided.

@dfa1
Copy link
Contributor

dfa1 commented Jun 1, 2023

@bbakerman what about using a single .handle?

        return fetchedValue
                .handle((result, exception) -> {
                    fetchCtx.onCompleted(result, exception);
                    if (exception != null) {
                        result = handleFetchingException(executionContext, dataFetchingEnvironment.get(), exception);
                    }
                    return unboxPossibleDataFetcherResult(executionContext, parameters, result);
                });

@bbakerman
Copy link
Member Author

What about using a single .handle?
Ahh I tried it - it wont work

The error handler returns CF<U> while .handle() needs to a <U> so we need to compose afterwards - I dont think there is any saving to be made here

protected <T> CompletableFuture<T> handleFetchingException(ExecutionContext executionContext,
DataFetchingEnvironment environment,
Throwable e) {
protected <T> CompletableFuture<T> handleFetchingException(
Copy link
Member Author

Choose a reason for hiding this comment

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

never used

*
* @throws java.lang.ClassCastException if it's not an Iterable
*/
protected Iterable<Object> toIterable(Object result) {
Copy link
Member Author

Choose a reason for hiding this comment

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

never used

@bbakerman bbakerman added the breaking change requires a new major version to be relased label Jun 2, 2023
@bbakerman bbakerman added this to the 2023 July milestone Jun 2, 2023
*
* @throws java.lang.ClassCastException if it's not an Iterable
*/
protected Iterable<Object> toIterable(Object result) {
Copy link
Member Author

Choose a reason for hiding this comment

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

technically a breaking change BUT a low risk one

@bbakerman bbakerman added the performance work that is primarily targeted as performance improvements label Jun 2, 2023
@bbakerman bbakerman added this pull request to the merge queue Jun 7, 2023
Merged via the queue into master with commit d4f1756 Jun 7, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change requires a new major version to be relased performance work that is primarily targeted as performance improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants