Skip to content

PM-1518 Fix 429 too many requests error #1170

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

Merged
merged 1 commit into from
Aug 1, 2025
Merged

PM-1518 Fix 429 too many requests error #1170

merged 1 commit into from
Aug 1, 2025

Conversation

himaniraghav3
Copy link
Collaborator

Related JIRA Ticket:

https://topcoder.atlassian.net/browse/PM-1518

What's in this PR?

Use sleep to introduce delays between chunked requests.
Sequentially fetch chunks with a delay (200ms) between requests.

@himaniraghav3 himaniraghav3 requested a review from kkartunov August 1, 2025 06:45
@@ -11,6 +11,8 @@ const baseUrl = `${EnvironmentConfig.API.V5}/projects`

export type ProjectsResponse = SWRResponse<Project[], Project[]>

const sleep = (ms: number): Promise<()=> void> => new Promise(resolve => { setTimeout(resolve, ms) })
Copy link

Choose a reason for hiding this comment

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

The return type of the sleep function is incorrect. It should be Promise<void> instead of Promise<()=> void>. The function resolves without returning any value, so the correct type should reflect that.

const allResults: Project[] = []

for (const chunkIds of idChunks) {
// eslint-disable-next-line no-await-in-loop
Copy link

Choose a reason for hiding this comment

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

Consider removing the // eslint-disable-next-line no-await-in-loop comment and refactoring the code to avoid using await inside a loop. This can be achieved by using Promise.all with map to handle asynchronous operations concurrently, which can improve performance.

allResults.push(...response)

// Rate limit: delay 200ms between calls
// eslint-disable-next-line no-await-in-loop
Copy link

Choose a reason for hiding this comment

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

The // eslint-disable-next-line no-await-in-loop comment indicates a potential issue with using await inside a loop. Consider refactoring the code to avoid this pattern, possibly by using Promise.all to handle asynchronous operations concurrently.

@himaniraghav3 himaniraghav3 merged commit b62d5c7 into dev Aug 1, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants