Openstatus www.openstatus.dev

๐Ÿ› public status (#679)

authored by

Thibault Le Ouay and committed by
GitHub
3e090c9f 2075793e

+29 -19
+29 -19
apps/server/src/public/status.ts
··· 42 42 } 43 43 44 44 startTime(c, "database"); 45 - const { 46 - monitorData, 47 - pageStatusReportData, 48 - monitorStatusReportData, 49 - ongoingIncidents, 50 - } = await getStatusPageData(slug); 45 + 46 + const currentPage = await db 47 + .select() 48 + .from(page) 49 + .where(eq(page.slug, slug)) 50 + .get(); 51 + 52 + console.log(currentPage); 53 + if (!currentPage) { 54 + return c.json({ status: Status.Unknown }); 55 + } 56 + 57 + const { pageStatusReportData, monitorStatusReportData, ongoingIncidents } = 58 + await getStatusPageData(currentPage.id); 51 59 endTime(c, "database"); 52 60 53 61 const isStatusReport = [ ··· 57 65 if (!data.status_report) return false; 58 66 return !["monitoring", "resolved"].includes(data.status_report.status); 59 67 }); 60 - 61 68 function getStatus() { 62 69 if (isStatusReport) return Status.Incident; 63 70 // if (monitorData.length === 0) return Status.Unknown; ··· 70 77 return c.json({ status }); 71 78 }); 72 79 73 - async function getStatusPageData(slug: string) { 80 + async function getStatusPageData(pageId: number) { 74 81 const monitorData = await db 75 82 .select() 76 83 .from(monitorsToPages) 77 - .leftJoin( 84 + .innerJoin( 78 85 monitor, 79 86 // REMINDER: query only active monitors as they are the ones that are displayed on the status page 80 - and(eq(monitorsToPages.monitorId, monitor.id), eq(monitor.active, true)), 87 + and( 88 + eq(monitorsToPages.monitorId, monitor.id), 89 + eq(monitor.active, true), 90 + eq(monitorsToPages.pageId, pageId), 91 + ), 81 92 ) 82 - .leftJoin(page, eq(monitorsToPages.pageId, page.id)) 83 - .where(eq(page.slug, slug)) 93 + 84 94 .all(); 85 95 86 96 const monitorIds = monitorData.map((i) => i.monitor?.id).filter(notEmpty); ··· 96 106 const monitorStatusReportQuery = db 97 107 .select() 98 108 .from(monitorsToStatusReport) 99 - .leftJoin( 109 + .innerJoin( 100 110 statusReport, 101 111 eq(monitorsToStatusReport.statusReportId, statusReport.id), 102 112 ) 103 113 .where(inArray(monitorsToStatusReport.monitorId, monitorIds)) 104 114 .all(); 105 115 106 - // REMINDER: the query can overlap with the previous one 107 116 const pageStatusReportDataQuery = db 108 117 .select() 109 118 .from(pagesToStatusReports) 110 - .leftJoin( 119 + .innerJoin( 111 120 statusReport, 112 - eq(pagesToStatusReports.statusReportId, statusReport.id), 121 + and( 122 + eq(pagesToStatusReports.statusReportId, statusReport.id), 123 + eq(pagesToStatusReports.pageId, pageId), 124 + ), 113 125 ) 114 - .leftJoin(page, eq(pagesToStatusReports.pageId, page.id)) 115 - .where(eq(page.slug, slug)) 116 126 .all(); 117 127 118 128 const ongoingIncidentsQuery = db ··· 134 144 ]); 135 145 136 146 return { 137 - monitorData, 147 + // monitorData, 138 148 pageStatusReportData, 139 149 monitorStatusReportData, 140 150 ongoingIncidents,