Skip to content

Commit 6ef9ebb

Browse files
committed
fix: batch calls to member api
Signed-off-by: Rakib Ansary <rakibansary@topcoder.com>
1 parent 10073b7 commit 6ef9ebb

File tree

1 file changed

+12
-5
lines changed
  • src/apps/wallet-admin/src/lib/services

1 file changed

+12
-5
lines changed

src/apps/wallet-admin/src/lib/services/wallet.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,14 +295,21 @@ export async function getRecipientViewURL(): Promise<TransactionResponse> {
295295
}
296296

297297
export async function getMemberHandle(userIds: string[]): Promise<Map<number, string>> {
298-
const url = `${memberApiBaseUrl}?userIds=[${userIds.join(',')}]&fields=handle,userId`
299-
const response = await xhrGetAsync<{ handle: string, userId: number }[]>(url)
298+
const BATCH_SIZE = 50
300299

301300
const handleMap = new Map<number, string>()
302301

303-
response.forEach(member => {
304-
handleMap.set(member.userId, member.handle)
305-
})
302+
for (let i = 0; i < userIds.length; i += BATCH_SIZE) {
303+
const batch = userIds.slice(i, i + BATCH_SIZE)
304+
305+
const url = `${memberApiBaseUrl}?userIds=[${batch.join(',')}]&fields=handle,userId`
306+
// eslint-disable-next-line no-await-in-loop
307+
const response = await xhrGetAsync<{ handle: string, userId: number }[]>(url)
308+
309+
response.forEach(member => {
310+
handleMap.set(member.userId, member.handle)
311+
})
312+
}
306313

307314
return handleMap
308315
}

0 commit comments

Comments
 (0)