Skip to content

PageableExecutionUtils returns too many results for content #2492

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

Closed
sniffertine opened this issue Nov 5, 2021 · 1 comment
Closed

PageableExecutionUtils returns too many results for content #2492

sniffertine opened this issue Nov 5, 2021 · 1 comment
Assignees
Labels
type: documentation A documentation update

Comments

@sniffertine
Copy link

sniffertine commented Nov 5, 2021

I have used PageableExecutionUtils for the first time today and think there might be a bug. The returned page seems to always contain the whole content, not a sublist of the given input as I would expect. Or is there a misunderstanding on my side that I am not seeing?

The following simple test illustrates the issue:

    @Test
    void testPageContent() {
        List<Integer> content = List.of(1, 2, 3, 4, 5, 6, 7, 8, 9);
        Page<Integer> page = PageableExecutionUtils.getPage(content, PageRequest.of(1, 4), content::size);

        assertThat(page.getTotalElements()).isEqualTo(9);
        assertThat(page.getTotalPages()).isEqualTo(3);
        assertThat(page.getNumber()).isEqualTo(1);
        assertThat(page.getSize()).isEqualTo(4);
        assertThat(page.getNumberOfElements()).isEqualTo(4); //fails
        assertThat(page.getContent().size()).isEqualTo(4); //fails
        assertThat(page).containsExactly(5, 6, 7, 8); //fails
    }

Cheers
Stefan

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 5, 2021
@mp911de
Copy link
Member

mp911de commented Nov 8, 2021

PageableExecutionUtils assumes that content is a result of applying Pageable to the query returning the actual content. We haven't covered the case that content might be greater than Pageable#getPageSize as queries with JPA/MongoDB and other stores respect the limitation of rows/documents on the server side. We might want to extend our documentation though to reflect this assumption.

@christophstrobl christophstrobl added type: documentation A documentation update and removed status: waiting-for-triage An issue we've not yet triaged labels Nov 8, 2021
mp911de added a commit that referenced this issue Nov 9, 2021
mp911de added a commit that referenced this issue Nov 9, 2021
@mp911de mp911de closed this as completed in 55b83df Nov 9, 2021
@mp911de mp911de added this to the 2.4.15 (2020.0.15) milestone Nov 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation A documentation update
Projects
None yet
Development

No branches or pull requests

4 participants