неадекватный total при пагинации springboot
при различных параметрах size получаю разный total.
при size > количество элементов, total верный
при size <= количество элементов, total неверный
public GenericPage<FilterUserDto> getAllUserIds(@RequestParam(value = "fullTextQuery", required = false) String fullTextQuery,
@ApiIgnore Pageable pageable) {
Page<FilterUserDto> allUserIds = statisticsService.getAllUserIds(fullTextQuery, pageable);
return new GenericPage<>(allUserIds.getContent(), allUserIds.getTotalElements());
}
верный тотал:
tasks/background/orgs/allUserIds?size=13
{"id":"JTC_SergeySV2_AdminDBO2","name":"JTC_SergeySV2_AdminDBO2"},{"id":"cf981379-68ed-42b0-b283-c733af367c6a","name":"system"}],"total":12}
неверный тотал:
tasks/background/orgs/allUserIds?size=12
{"id":"JTC_SergeySV2_AdminDBO2","name":"JTC_SergeySV2_AdminDBO2"},{"id":"cf981379-68ed-42b0-b283-c733af367c6a","name":"system"}],"total":2914}
сервис:
public Page<FilterUserDto> getAllUserIds(String fullTextQuery, Pageable pageable) {
return taskRepository.getTaskUsers(formatFullTextQuery(fullTextQuery), pageable)
.map(u -> new FilterUserDto(u.getId(), u.getName()));
}
репозиторий:
@Query(" SELECT distinct t.user " +
" FROM Task t " +
" WHERE :fullTextQuery is null or UPPER(t.user.name) like :fullTextQuery" +
" order by t.user.name")
Page<User> getTaskUsers(@Param("fullTextQuery") String fullTextQuery, Pageable pageable);