From b9095993bd72cda53d094469769f588d50658023 Mon Sep 17 00:00:00 2001 From: Tobi Saputra Date: Fri, 7 Feb 2025 21:06:21 +0700 Subject: [PATCH] fix: requests take too long --- src/utils/get/getComments.ts | 9 ++++++--- src/utils/get/getProfile.ts | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/utils/get/getComments.ts b/src/utils/get/getComments.ts index 93b8131..36cd846 100644 --- a/src/utils/get/getComments.ts +++ b/src/utils/get/getComments.ts @@ -105,7 +105,7 @@ const parseComments = async ( const result = await requestComments(id, cursor, proxy) - // Check if the result has more comments + // Check if the result has more comments & if (result.has_more === 0) hasMore = false result.comments?.forEach((v: any) => { @@ -162,6 +162,7 @@ const parseComments = async ( if (commentLimit) { let loopCount = Math.floor(commentLimit / 50) if (counter >= loopCount) hasMore = false + break } hasMore = result.has_more === 1 @@ -169,8 +170,10 @@ const parseComments = async ( counter++ } + const response = + total > commentLimit ? comments.slice(0, commentLimit) : comments return { - total: total, - comments: commentLimit ? comments.slice(0, commentLimit) : comments + total: response.length, + comments: response } } diff --git a/src/utils/get/getProfile.ts b/src/utils/get/getProfile.ts index dc7b521..418e3c0 100644 --- a/src/utils/get/getProfile.ts +++ b/src/utils/get/getProfile.ts @@ -247,6 +247,7 @@ const parsePosts = async ( if (postLimit !== 0) { let loopCount = Math.floor(postLimit / 30) if (counter >= loopCount) hasMore = false + break } hasMore = result.hasMore