From 1a8bf3fdcb45ea1a5b35bcceeb1b1154439918d2 Mon Sep 17 00:00:00 2001 From: Priyank Rajai Date: Fri, 2 Aug 2024 01:28:13 +0530 Subject: [PATCH] Refactor: optimizing monitor page (#970) * refactor: using promise.all for multiple api requests * ci: apply automated fixes * refactor: moving search params condition to top * ci: apply automated fixes * refactor: moving isLimitReached to promise.all after getting all the monitors * refartor: using promise.all for metrics and data --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- .../(dashboard)/monitors/(overview)/page.tsx | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/(overview)/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/(overview)/page.tsx index 27966126..3dcc5f8d 100644 --- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/(overview)/page.tsx +++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/(overview)/page.tsx @@ -70,19 +70,20 @@ export default async function MonitorPage({ // use Suspense and Client call instead? const monitorsWithData = await Promise.all( monitors.map(async (monitor) => { - const metrics = await tb.endpointMetrics("1d")( - { - monitorId: String(monitor.id), - }, - { cache: "no-store", revalidate: 0 }, - ); - - const data = await tb.endpointStatusPeriod("7d")( - { - monitorId: String(monitor.id), - }, - { cache: "no-store", revalidate: 0 }, - ); + const [metrics, data] = await Promise.all([ + tb.endpointMetrics("1d")( + { + monitorId: String(monitor.id), + }, + { cache: "no-store", revalidate: 0 }, + ), + tb.endpointStatusPeriod("7d")( + { + monitorId: String(monitor.id), + }, + { cache: "no-store", revalidate: 0 }, + ), + ]); const [current] = metrics?.sort((a, b) => (a.lastTimestamp || 0) - (b.lastTimestamp || 0) < 0 ? 1 : -1, -- 2.51.2