From 9172a87f5d51d0b7573a8c92188843aef455db9e Mon Sep 17 00:00:00 2001 From: VrianCao <45995071+VrianCao@users.noreply.github.com> Date: Tue, 14 Apr 2026 11:39:30 +0000 Subject: [PATCH] perf(homepage): reduce artifact JSON escaping --- apps/worker/src/snapshots/public-homepage.ts | 40 ++++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/apps/worker/src/snapshots/public-homepage.ts b/apps/worker/src/snapshots/public-homepage.ts index 21917b2..3b7586e 100644 --- a/apps/worker/src/snapshots/public-homepage.ts +++ b/apps/worker/src/snapshots/public-homepage.ts @@ -130,10 +130,10 @@ function buildUptimeStripSvg( const x = index * (barWidth + gap); const fill = uptimeFillFromMilli(strip.uptime_pct_milli[index]); rects.push( - ``, + ``, ); } - return ``; + return ``; } function buildHeartbeatStripSvg( @@ -156,10 +156,10 @@ function buildHeartbeatStripSvg( ); const y = height - barHeight; rects.push( - ``, + ``, ); } - return ``; + return ``; } function renderIncidentCard( @@ -170,10 +170,10 @@ function renderIncidentCard( incident.impact === 'major' || incident.impact === 'critical' ? 'down' : 'paused'; const parts: string[] = [ - `

${escapeHtml(incident.title)}

${escapeHtml(incident.impact)}
${formatTimestamp(incident.started_at)}
`, + `

${escapeHtml(incident.title)}

${escapeHtml(incident.impact)}
${formatTimestamp(incident.started_at)}
`, ]; if (incident.message) { - parts.push(`

${escapeHtml(incident.message)}

`); + parts.push(`

${escapeHtml(incident.message)}

`); } parts.push('
'); return parts.join(''); @@ -194,13 +194,13 @@ function renderMaintenanceCard( } const parts: string[] = [ - `

${escapeHtml(window.title)}

${formatTimestamp(window.starts_at)} - ${formatTimestamp(window.ends_at)}
`, + `

${escapeHtml(window.title)}

${formatTimestamp(window.starts_at)} - ${formatTimestamp(window.ends_at)}
`, ]; if (affected.length > 0) { - parts.push(`
Affected: ${affected.join(', ')}
`); + parts.push(`
Affected: ${affected.join(', ')}
`); } if (window.message) { - parts.push(`

${escapeHtml(window.message)}

`); + parts.push(`

${escapeHtml(window.message)}

`); } parts.push('
'); return parts.join(''); @@ -247,12 +247,12 @@ function renderPreload( : 'Never checked'; monitorCardsParts.push( - `
${escapeHtml(monitor.name)}
${escapeHtml(monitor.type)}
${escapeHtml(uptimePct)}${statusLabel}
Availability (30d)
${buildUptimeStripSvg(monitor.uptime_day_strip)}
Recent checks
${buildHeartbeatStripSvg(monitor.heartbeat_strip)}
${lastCheckedLabel}
`, + `
${escapeHtml(monitor.name)}
${escapeHtml(monitor.type)}
${escapeHtml(uptimePct)}${statusLabel}
Availability (30d)
${buildUptimeStripSvg(monitor.uptime_day_strip)}
Recent checks
${buildHeartbeatStripSvg(monitor.heartbeat_strip)}
${lastCheckedLabel}
`, ); } groupedMonitorsParts.push( - `

${escapeHtml(groupName)}

${groupMonitors.length}
${monitorCardsParts.join('')}
`, + `

${escapeHtml(groupName)}

${groupMonitors.length}
${monitorCardsParts.join('')}
`, ); } @@ -274,7 +274,7 @@ function renderPreload( } } - maintenanceSection = `

Scheduled Maintenance

${activeCards.length > 0 ? `
${activeCards.join('')}
` : ''}${upcomingCards.length > 0 ? `
${upcomingCards.join('')}
` : ''}
`; + maintenanceSection = `

Scheduled Maintenance

${activeCards.length > 0 ? `
${activeCards.join('')}
` : ''}${upcomingCards.length > 0 ? `
${upcomingCards.join('')}
` : ''}
`; } let incidentSection = ''; @@ -283,26 +283,26 @@ function renderPreload( for (const incident of snapshot.active_incidents) { incidentCards.push(renderIncidentCard(incident, formatTimestamp)); } - incidentSection = `

Active Incidents

${incidentCards.join('')}
`; + incidentSection = `

Active Incidents

${incidentCards.join('')}
`; } const incidentHistory = snapshot.resolved_incident_preview ? renderIncidentCard(snapshot.resolved_incident_preview, formatTimestamp) - : '
No past incidents
'; + : `
No past incidents
`; const maintenanceHistory = snapshot.maintenance_history_preview ? monitorNames ? renderMaintenanceCard(snapshot.maintenance_history_preview, monitorNames, formatTimestamp) - : '
No past maintenance
' - : '
No past maintenance
'; + : `
No past maintenance
` + : `
No past maintenance
`; const descriptionHtml = siteDescription - ? `
${escapeHtml(siteDescription)}
` + ? `
${escapeHtml(siteDescription)}
` : ''; const hiddenMonitorMessage = hiddenMonitorCount > 0 - ? `
${hiddenMonitorCount} more services will appear after the app finishes loading.
` + ? `
${hiddenMonitorCount} more services will appear after the app finishes loading.
` : ''; - return `
${escapeHtml(siteTitle)}
${descriptionHtml}
${escapeHtml(overall)}
${escapeHtml(bannerTitle)}
Updated: ${formatTimestamp(generatedAt)}
${maintenanceSection}${incidentSection}

Services

${groupedMonitorsParts.join('')}${hiddenMonitorMessage}

Incident History

${incidentHistory}

Maintenance History

${maintenanceHistory}
`; + return `
${escapeHtml(siteTitle)}
${descriptionHtml}
${escapeHtml(overall)}
${escapeHtml(bannerTitle)}
Updated: ${formatTimestamp(generatedAt)}
${maintenanceSection}${incidentSection}

Services

${groupedMonitorsParts.join('')}${hiddenMonitorMessage}

Incident History

${incidentHistory}

Maintenance History

${maintenanceHistory}
`; } export function buildHomepageRenderArtifact( @@ -337,7 +337,7 @@ export function buildHomepageRenderArtifact( return { generated_at: snapshot.generated_at, - preload_html: `
${renderPreload(bootstrapSnapshot, allMonitorNames)}
`, + preload_html: `
${renderPreload(bootstrapSnapshot, allMonitorNames)}
`, snapshot: bootstrapSnapshot, meta_title: metaTitle, meta_description: metaDescription,