Skip to content

Commit 5ea55f4

Browse files
committed
Fetch paginated payments and counts in parallel
This speeds up loading of the payments page for some filters.
1 parent 50c53dd commit 5ea55f4

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

pages/payments/index.tsx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -224,16 +224,16 @@ export default function Payments ({ user, userId, organization }: PaybuttonsProp
224224
paymentsCountUrl += `${paymentsCountUrl.includes('?') ? '&' : '?'}endDate=${endDate}`
225225
}
226226

227-
const paymentsResponse = await fetch(url, {
228-
headers: {
229-
Timezone: timezone
230-
}
231-
})
232-
233-
const paymentsCountResponse = await fetch(
234-
paymentsCountUrl,
235-
{ headers: { Timezone: timezone } }
236-
)
227+
const [paymentsResponse, paymentsCountResponse] = await Promise.all([
228+
fetch(url, {
229+
headers: {
230+
Timezone: timezone
231+
}
232+
}),
233+
fetch(paymentsCountUrl, {
234+
headers: { Timezone: timezone }
235+
})
236+
])
237237

238238
if (!paymentsResponse.ok || !paymentsCountResponse.ok) {
239239
console.log('paymentsResponse status', paymentsResponse.status)
@@ -243,8 +243,10 @@ export default function Payments ({ user, userId, organization }: PaybuttonsProp
243243
throw new Error('Failed to fetch payments or count')
244244
}
245245

246-
const totalCount = await paymentsCountResponse.json()
247-
const payments = await paymentsResponse.json()
246+
const [payments, totalCount] = await Promise.all([
247+
paymentsResponse.json(),
248+
paymentsCountResponse.json()
249+
])
248250

249251
return { data: payments, totalCount }
250252
} catch (error) {

0 commit comments

Comments
 (0)