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
This commit is contained in:
2026-02-18 10:24:10 +01:00
parent 9e9bc9d3aa
commit e5b414ea76
3 changed files with 11 additions and 2 deletions

View File

@@ -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(

View File

@@ -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<string, string> = {
'Content-Type': 'application/json',

View File

@@ -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:', {