From e5b414ea76d99a6b0dbaf9c3e9a433e546bd16f3 Mon Sep 17 00:00:00 2001 From: Marc Mintel Date: Wed, 18 Feb 2026 10:24:10 +0100 Subject: [PATCH] perf: optimize server-side analytics and notifications to resolve 32s transaction delay - Added 5s timeout to GotifyNotificationService - Reduced timeout to 2s in UmamiAnalyticsService - Implemented non-blocking analytics tracking in layout using Next.js after() API --- app/[locale]/layout.tsx | 5 ++++- lib/services/analytics/umami-analytics-service.ts | 2 +- lib/services/notifications/gotify-notification-service.ts | 6 ++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/[locale]/layout.tsx b/app/[locale]/layout.tsx index d360aaa3..b2f0b050 100644 --- a/app/[locale]/layout.tsx +++ b/app/[locale]/layout.tsx @@ -88,7 +88,10 @@ export default async function Layout(props: { }); } - serverServices.analytics.trackPageview(); + const { after } = await import('next/server'); + after(() => { + serverServices.analytics.trackPageview(); + }); } catch { if (process.env.NODE_ENV !== 'production' || !process.env.CI) { console.warn( diff --git a/lib/services/analytics/umami-analytics-service.ts b/lib/services/analytics/umami-analytics-service.ts index cf70c6d0..edea6182 100644 --- a/lib/services/analytics/umami-analytics-service.ts +++ b/lib/services/analytics/umami-analytics-service.ts @@ -91,7 +91,7 @@ export class UmamiAnalyticsService implements AnalyticsService { // Add a timeout to prevent hanging requests const controller = new AbortController(); - const timeoutId = setTimeout(() => controller.abort(), 10000); // 10s timeout + const timeoutId = setTimeout(() => controller.abort(), 2000); // 2s timeout const headers: Record = { 'Content-Type': 'application/json', diff --git a/lib/services/notifications/gotify-notification-service.ts b/lib/services/notifications/gotify-notification-service.ts index d18bfa04..351396e0 100644 --- a/lib/services/notifications/gotify-notification-service.ts +++ b/lib/services/notifications/gotify-notification-service.ts @@ -17,6 +17,9 @@ export class GotifyNotificationService implements NotificationService { const url = new URL('message', this.config.url); url.searchParams.set('token', this.config.token); + const controller = new AbortController(); + const timeoutId = setTimeout(() => controller.abort(), 5000); + const response = await fetch(url.toString(), { method: 'POST', headers: { @@ -27,8 +30,11 @@ export class GotifyNotificationService implements NotificationService { message, priority, }), + signal: controller.signal, }); + clearTimeout(timeoutId); + if (!response.ok) { const errorText = await response.text(); console.error('Gotify notification failed:', {