strapi / strapi

πŸš€ Strapi is the leading open-source headless CMS. It’s 100% JavaScript/TypeScript, fully customizable and developer-first.
https://strapi.io
Other
60.67k stars 7.58k forks source link

fix: document service find many pagination #20178

Closed Marc-Roig closed 1 week ago

Marc-Roig commented 3 weeks ago

What does it do?

We allowed page & pageSize parameters on find Many, but those params were not properly converted to the offset & limit database params.

This PR proposes a fix, which always converts pagination params to offset and limit, so both page & pagesize, and start & limit works on the findMany method, or any other that accepts pagination.

How to test

Go to the List View of the CMS, and the pages should load correctlly, 10 entities at a time

Fixes https://github.com/strapi/strapi/issues/20005

Marc-Roig commented 3 weeks ago

I am creating tests in the meantime

vercel[bot] commented 3 weeks ago

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Comments Updated (UTC)
contributor-docs βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback May 6, 2024 0:24am
Marc-Roig commented 3 weeks ago

IMHO we should remove all notion of page & pageSize on the db layer.

agree on this, this would mean removing the "findPage" method from the db layer, which atm I do not see it as a good idea

For those page to limit/offset transforms I'm not sure we should do it here, the convertQueryParams is supposed to pass the same params it receives but formatted, this can have a huge impact on people using it and I'm not sure I see a good enough reason to do that here πŸ€”

Alright :) , two solutions then:

I would go for the first option, wdyt?

alexandrebodin commented 3 weeks ago

IMHO we should remove all notion of page & pageSize on the db layer.

agree on this, this would mean removing the "findPage" method from the db layer, which atm I do not see it as a good idea

For those page to limit/offset transforms I'm not sure we should do it here, the convertQueryParams is supposed to pass the same params it receives but formatted, this can have a huge impact on people using it and I'm not sure I see a good enough reason to do that here πŸ€”

Alright :) , two solutions then:

  • Transform page params to limit&offset in the doc service findMany pipe function
  • Prevent users from using pagination params in the findMany

I would go for the first option, wdyt?

How did we support it in the findMany of the entityService ? I think we can go with this, even if long term I'm not sure I would

Marc-Roig commented 3 weeks ago

How did we support it in the findMany of the entityService ? I think we can even if long term I'm not sure I would

We did not support it on the findMany, we had a findPage method

alexandrebodin commented 3 weeks ago

How did we support it in the findMany of the entityService ? I think we can even if long term I'm not sure I would

We did not support it on the findMany, we had a findPage method

I don't think we have enough bandwidth to just complete drop that and refactor everywhere else, let's support it in the findMany for convenience

alexandrebodin commented 3 weeks ago

How did we support it in the findMany of the entityService ? I think we can even if long term I'm not sure I would

We did not support it on the findMany, we had a findPage method

I don't think we have enough bandwidth to just complete drop that and refactor everywhere else, let's support it in the findMany for convenience. side note if we do support it I feel like there was no real point of dropping findPage πŸ€”

Marc-Roig commented 3 weeks ago

🀝 will start working on that

alexandrebodin commented 3 weeks ago

How did we support it in the findMany of the entityService ? I think we can even if long term I'm not sure I would

We did not support it on the findMany, we had a findPage method

I don't think we have enough bandwidth to just complete drop that and refactor everywhere else, let's support it in the findMany for convenience. side note if we do support it I feel like there was no real point of dropping findPage πŸ€”

Marc-Roig commented 3 weeks ago

No strong opinion, findPage did support both page&pageSize and start&limit, just that the response included the page count.

Keeping it would make the life a bit easier for users (specially migrating from v4), also would introduce a 4th "findX" method to document.

If findPage supported both start&limit I think it would make sense for the findmany to support those too. And we can always add the findPage method again later on, wdyt?

alexandrebodin commented 3 weeks ago

No strong opinion, findPage did support both page&pageSize and start&limit, just that the response included the page count.

Keeping it would make the life a bit easier for users (specially migrating from v4), also would introduce a 4th "findX" method to document.

If findPage supported both start&limit I think it would make sense for the findmany to support those too. And we can always add the findPage method again later on, wdyt?

I don't think findMany should know what's a page at all that's my concern, if we added cursor based pagination we would not support it in findMany butexpect it to be converted to a limit & a filter on a column,

Marc-Roig commented 3 weeks ago

alright ! do you think we should reintroduce the findPage method in the doc service then?

Marc-Roig commented 2 weeks ago

I am going to add some more api tests today, logic should stay the same

Marc-Roig commented 1 week ago

@alexandrebodin created tests for the CM, and content api tests where skipped :hehe: everything should be covered.

Not checked, but do you think we need to work on the graphql part too?

alexandrebodin commented 1 week ago

@alexandrebodin created tests for the CM, and content api tests where skipped :hehe: everything should be covered.

Not checked, but do you think we need to work on the graphql part too?

Niceee all good then,

For graphql we use the utils but that one you didn't change so we should be good. orther checking if we have some tests that exist or not though