0

I would like to make paginated database calls in-parallel/asynchronous each page returning unique results. I am using project-reactor with java-8. With below code somehow its fetching duplicate records in some pages. When I query each page directly on DB, I get unique set of results in each page.

List<Mono<List<User>>> usersMonos = new ArrayList<>();
IntStream.range(1, 5).forEach(i -> {
  usersMonos.add(Mono.fromSupplier(() -> {
  int from = (1 + (10000 * (i - 1)));
  int to = 10000 * i;
  List<User> users = userMapper.getPaginatedUser(userId, from, to);
  return users;
 }));
});

List<User> allPageUsers = Flux.zip(usersMonos, new UserTransformer())
            .collectList()
            .block()
            .stream()
            .flatMap(List::stream)
            .collect(Collectors.toList());
  • Any help on this please? – Prasad Kulkarni Jun 06 '19 at 07:30
  • More information on what your code is doing and what it should be doing would be very usefull. As far as I understod you want to remove duplicates from a stream. Have you tried using the [distinct](https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html#distinct--) method of the Stream class? Maybe also have a look at [this post](https://stackoverflow.com/questions/23699371/java-8-distinct-by-property) – Tobias Jun 06 '19 at 07:47

0 Answers0