Openstatus www.openstatus.dev

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>

authored by

Priyank Rajai
autofix-ci[bot]
and committed by
GitHub
1a8bf3fd 8986eb92

+14 -13
+14 -13
apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/(overview)/page.tsx
··· 70 70 // use Suspense and Client call instead? 71 71 const monitorsWithData = await Promise.all( 72 72 monitors.map(async (monitor) => { 73 - const metrics = await tb.endpointMetrics("1d")( 74 - { 75 - monitorId: String(monitor.id), 76 - }, 77 - { cache: "no-store", revalidate: 0 }, 78 - ); 79 - 80 - const data = await tb.endpointStatusPeriod("7d")( 81 - { 82 - monitorId: String(monitor.id), 83 - }, 84 - { cache: "no-store", revalidate: 0 }, 85 - ); 73 + const [metrics, data] = await Promise.all([ 74 + tb.endpointMetrics("1d")( 75 + { 76 + monitorId: String(monitor.id), 77 + }, 78 + { cache: "no-store", revalidate: 0 }, 79 + ), 80 + tb.endpointStatusPeriod("7d")( 81 + { 82 + monitorId: String(monitor.id), 83 + }, 84 + { cache: "no-store", revalidate: 0 }, 85 + ), 86 + ]); 86 87 87 88 const [current] = metrics?.sort((a, b) => 88 89 (a.lastTimestamp || 0) - (b.lastTimestamp || 0) < 0 ? 1 : -1,