Closed adelabd closed 2 years ago
That's indeed a bug on our side as we use flatMap
on Flux
when applying the callback.
Maybe just using flatMapSequential
should fix the problem.
concatMap
is the right choice.
I don't think so.
concatMap
=> Generation of inners and subscription: this operator waits for one inner to complete before generating the next one and subscribing to it.
In this specific case, it's not required to wait the previous inner complete before subscribe to the new one.
We just need to keep the order at the end, not to be sequential during the execution of each item.
flatMapSequential
seems to be more appropriate for this use case.
flatMapSequential
=> Transform the elements emitted by this Flux asynchronously into Publishers, then flatten these inner publishers into a single Flux, but merge them in the order of their source element.
With a flatMapSequential
operator we would increase concurrency by number of stream elements * 16
, and that impact is much more harmful than delaying subscription/completion. In general, callbacks on result streams aren't intended to create a N+1
problem.
When we try to get a list of sorted entities, the order is lost if we use the
EntityCallback
. I can confirm that the order is well respected in theAfterConvertCallback
(I put a breakpoint in theonAfterConvert
method and I can see each country sorted bycountryName
) However, as theAfterConvertCallback
is making some reactive call, the order is lost at the end and the methodfindAllByOrderByCountryName
does not return an ordered flux anymore.If I remove the
EntityCallback
, the sorting is well respected.Entity country
Country repository using ReactiveSorting