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

NOTIF-55 Use Multi when relevant, replace with Uni<List> otherwise #235

Merged
merged 1 commit into from
May 17, 2021

Conversation

gwenneg
Copy link
Member

@gwenneg gwenneg commented May 10, 2021

This is preparation work for #202.

I found something about the response time issue with quarkus-resteasy-reactive: the response time can be bad only with APIs that return Multi. There's no problem with methods returning Uni<List>, which should always be the type we use anyway because we never need to stream data back to the client. I created quarkusio/quarkus#17094 to report the issue with Multi to the Quarkus team.

Since we're using Multi in many places for wrong reasons, I did some spring cleaning and replaced Multi with Uni<List>. A few methods could be cleaned further but I chose not to because they will be removed with phase 2 of behavior groups.

Here are some ground rules for future developments:

  • The persistence layer (*Resources classes) should not return Multi unless there's a very good reason to do so (usually, there's not).
  • The API layer (*Service classes) should not return Multi unless we need to stream data back to the client (that's very unlikely in this app).
  • We should refrain from using Multi to transform items from Uni<List>. There are situations when it makes sense but most of the time it doesn't. In particular, side-effects should be implemented with onItem().invoke() (synchronous, for code that will not block the I/O thread) or onItem().call() (asynchronous, for DB queries for example).

* - database queries are executed in an asynchronous way using `.onItem().call(...)`
* - side-effects are executed in a synchronous way using `.onItem().invoke(...)`
*/
return Uni.createFrom().item(() -> new SettingsValues())
Copy link
Member Author

Choose a reason for hiding this comment

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

This is roughly the same code than before but we're no longer using Multi in this method.

@gwenneg gwenneg force-pushed the replace-multi-with-uni branch from ab72e11 to 65e698b Compare May 10, 2021 08:17
@gwenneg gwenneg marked this pull request as ready for review May 10, 2021 08:17
@gwenneg gwenneg requested a review from josejulio May 10, 2021 08:17
@gwenneg
Copy link
Member Author

gwenneg commented May 10, 2021

Unlike #202 (see this), this PR can be merged as soon as the review is done.

@gwenneg gwenneg force-pushed the replace-multi-with-uni branch 2 times, most recently from f891ac3 to d5d589a Compare May 12, 2021 07:35
@gwenneg
Copy link
Member Author

gwenneg commented May 12, 2021

Rebased and fixed conflicts.

@josejulio
Copy link
Member

Rebased and fixed conflicts.

sorry, merged something and there is one conflict now

@gwenneg gwenneg force-pushed the replace-multi-with-uni branch from d5d589a to de2b789 Compare May 17, 2021 06:42
@gwenneg
Copy link
Member Author

gwenneg commented May 17, 2021

I solved the conflict. Thanks for the review!

@gwenneg gwenneg merged commit c085880 into RedHatInsights:master May 17, 2021
@gwenneg gwenneg deleted the replace-multi-with-uni branch May 17, 2021 06:57
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