Skip to content
This repository was archived by the owner on Dec 27, 2022. It is now read-only.

Conversation

@philippeauriach
Copy link

@philippeauriach philippeauriach commented Apr 30, 2021

Fix #104

Especially usefull on servers limiting the duration of requests (for example Heroku, which limits to 30sec each request).

Passing the loop parameter will perform multiple calls until all items are downloaded.

Readme.md updated with an example.

@strapi-cla
Copy link

strapi-cla commented Apr 30, 2021

CLA assistant check
All committers have signed the CLA.

Especially usefull on servers limiting the duration of requests (for example Heroku, which limits to 30sec each request).

Passing the loop parameter will perform multiple calls until all items are downloaded.
tonoli
tonoli previously approved these changes Jul 8, 2021
@philippeauriach
Copy link
Author

Hi @tonoli, thanks for reviewing. Could you tell what's missing in this issue before it could be merged ?

Copy link
Contributor

@remidej remidej left a comment

Choose a reason for hiding this comment

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

Thanks for taking the time to work on this! It can be a pretty good feature for a future release. I've added my review, don't hesitate to comment if you have questions

README.md Outdated
Comment on lines 159 to 160
api: { qs: { _sort: 'drop_date:DESC' } },
loop: 100,
Copy link
Contributor

Choose a reason for hiding this comment

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

The loop is an implementation detail of how we connect to the API. So I'd recommend moving the loop option inside of the api object

README.md Outdated

#### Multiple requests instead of a single large one

If you have many items in a collection and a single API call is a bit heavy for your server, you can split it into multiple requests.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
If you have many items in a collection and a single API call is a bit heavy for your server, you can split it into multiple requests.
When you have many items in a collection, a single API call can be a bit heavy for your server. In that case, you can split your data fetching into multiple requests.

src/fetch.js Outdated
const { apiURL, queryLimit, jwtToken, reporter } = ctx;

const { endpoint, api } = entityDefinition;
const { endpoint, api, loop } = entityDefinition;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above, I recommended getting the loop from the api object

src/fetch.js Outdated
);

try {
if (typeof loop === 'number') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please also check if it's a integer (no decimals) and >= 1

src/fetch.js Outdated
Comment on lines 39 to 44
reporter,
queryLimit,
requestOptions,
loop,
resultsAggreg = [],
_start = 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you replace these arguments with an object? This way it will be easier to read when calling that function

src/fetch.js Outdated
reporter,
queryLimit,
requestOptions,
loop,
Copy link
Contributor

Choose a reason for hiding this comment

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

We can make the default value 1

src/fetch.js Outdated
const newResults = resultsAggreg.concat(newlyFetched);
if (newlyFetched.length < loop || newResults.length >= queryLimit) {
reporter.info(`Loop fetching ended with ${newResults.length} items - ${requestOptions.url}`);
//ended
Copy link
Contributor

Choose a reason for hiding this comment

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

Please make this comment more explicit

src/fetch.js Outdated
//ended
return newResults;
}
return fetchLoop(reporter, queryLimit, requestOptions, loop, newResults, _start + loop);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a comment to make this recursion easier to read

src/index.js Outdated
if (typeof type === 'object') {
return {
endpoint: type.endpoint || (single ? type.name : pluralize(type.name)),
loop: type.loop,
Copy link
Contributor

Choose a reason for hiding this comment

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

This shouldn't be needed if we move it to the API object

@zsrl
Copy link

zsrl commented Aug 8, 2021

When can this feature be released?
I think I need it.
@philippeauriach @remidej

@philippeauriach
Copy link
Author

@remidej Changes made according to suggestions, thanks for your review. The only issue i didn't address is the part y ou ask for an explicit comment about the recursion, if you have an idea that would be nice ?
thanks

@FredWahlqvistDrop
Copy link

Hey @remidej, is there anything we can do to so this can be merged?

@laurenskling
Copy link
Collaborator

I would really like to have this. Currently I'm trying to load 90k models, but whatever I try, this this plugin wants to fetch them all at once. I've even tried to split request by adding multiple types in a loop with the same name with api: { qs: { _limit: limit, _start: limit * index } },, but that fetches all those queries at once, still making Strapi crash out of memory.

@Grouviere
Copy link

We're also needing this to be able to deploy on heroku. Is the only change blocking a missing comment ?

@soupette
Copy link
Contributor

I am closing the PR as a new version has been released, feel free to reopen it.

@soupette soupette closed this Feb 17, 2022
@laurenskling
Copy link
Collaborator

Since v2 is only compatible for Strapi 4, this fix would still be highly appreciated for us using Strapi 3 (MongoDB say hello 👋)

@laurenskling
Copy link
Collaborator

Would it be possible for this to be merged in as 1.1 @soupette ? Really, this plugin cannot be run without this fix. Without this, how would one load any data over a couple of hundred entries?
Since you are planning to go v2 for Strapi v4. Please merge this in as 1.1 for us poor souls running Strapi v3.

@soupette soupette reopened this Mar 11, 2022
@laurenskling
Copy link
Collaborator

I've been running this code for a while now using patch-package and it's been working great for me. On cold build.

I just realized that on incremental builds on Gatsby Cloud, the loop isn't running. My assumption here is that Gatsby Cloud incremental builds (which detect a Strapi webhook) run their installed version of the source plugin, not my patched one.

So still I would really really really love to see this feature released as a version 1.1 or something for us (still stuck at) running projects on Strapi 3. I don't see any downsides in doing so.

If this PR needs any work still, I would be super happy to work on it.

@soupette
Copy link
Contributor

@laurenskling have tried to the new version with the Strapi V4? It does support Gatsby incremental build

@laurenskling
Copy link
Collaborator

@soupette yes I know the v4 version is updated, but i'm running 10+ codebases on Strapi 3, and for all of them I need to: switch from mongo to sql, change all database fields to snake_case, update all my code, update all my plugins code, update my frontend code to use the new GraphQL output. It's not something I can do overnight, it will take me months, many months, before I'm ready to fully switch to v4.
I am in the process, but until it's ready (probably need a full year for it), i would really really like it if we can get these little code snippets with big impact into v3. Thanks.

@remidej
Copy link
Contributor

remidej commented Nov 30, 2022

Closing this as it's targeting Strapi v3, which reaches end of life in a month, so we won't maintain the v3 version of this source plugin either

@remidej remidej closed this Nov 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Paginate Strapi data requests

9 participants