Skip to content

fix: remove hydra:next when no items would be returned in the next cursor pagination page#6477

Closed
nesl247 wants to merge 2 commits intoapi-platform:4.2from
nesl247:remove-hydra-next-cursor-pagination-no-items
Closed

fix: remove hydra:next when no items would be returned in the next cursor pagination page#6477
nesl247 wants to merge 2 commits intoapi-platform:4.2from
nesl247:remove-hydra-next-cursor-pagination-no-items

Conversation

@nesl247
Copy link
Copy Markdown
Contributor

@nesl247 nesl247 commented Jul 18, 2024

When using cursor pagination, hydra:next is currently always set even when it wouldn't return any results.

$data['hydra:view']['@id'] = IriHelper::createIri($parsed['parts'], $parsed['parameters'], urlGenerationStrategy: $urlGenerationStrategy);

if (false !== $lastObject && \is_array($cursorPaginationAttribute)) {
if (false !== $lastObject && \is_array($cursorPaginationAttribute) && $pageTotalItems >= $itemsPerPage) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

when $pageTotalItems == $itemsPerPage we want to show hydra:view? Can you test this? I thought that with a cursor we did not know the amount of total items (no count)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We did test it out, we have it live in our production environment. This isn't perfect because it still could return no results on the next page, however, it prevents an empty page from showing hydra:next.

The logic is that with cursor pagination if you no longer have results on a page, the next one won't either because you are doing a less less than or greater than some identifier. Because it's only a comparison like that if it doesn't return enough results we can be certain the next page will return none.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

would you be able to add a test for this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry I haven't gotten around to adding a test here. It isn't forgotten though.

@stale
Copy link
Copy Markdown

stale Bot commented Nov 6, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale Bot added the stale label Nov 6, 2024
@nesl247
Copy link
Copy Markdown
Contributor Author

nesl247 commented Nov 7, 2024

It still needs to be resolved. I've not had time to add the proper tests to the PR unfortunately.

@stale stale Bot removed the stale label Nov 7, 2024
@VincentLanglet
Copy link
Copy Markdown
Contributor

Hi, are you still interested by this PR ? Do you have time to resolve the conflict/comment ?
Thanks

@soyuka soyuka force-pushed the remove-hydra-next-cursor-pagination-no-items branch from 84e12d6 to 09d235e Compare January 26, 2026 10:11
@soyuka soyuka changed the base branch from main to 4.2 January 26, 2026 10:35
@soyuka
Copy link
Copy Markdown
Member

soyuka commented Jan 26, 2026

I'm not a huge fan of this as it adds more computation then needed. I think that using JSON-LD users would just dereference and see an empty page which is probably fine.

@soyuka soyuka closed this Jan 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants