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:
@@ -88,7 +88,10 @@ export default async function Layout(props: {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
serverServices.analytics.trackPageview();
|
const { after } = await import('next/server');
|
||||||
|
after(() => {
|
||||||
|
serverServices.analytics.trackPageview();
|
||||||
|
});
|
||||||
} catch {
|
} catch {
|
||||||
if (process.env.NODE_ENV !== 'production' || !process.env.CI) {
|
if (process.env.NODE_ENV !== 'production' || !process.env.CI) {
|
||||||
console.warn(
|
console.warn(
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ export class UmamiAnalyticsService implements AnalyticsService {
|
|||||||
|
|
||||||
// Add a timeout to prevent hanging requests
|
// Add a timeout to prevent hanging requests
|
||||||
const controller = new AbortController();
|
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> = {
|
const headers: Record<string, string> = {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ export class GotifyNotificationService implements NotificationService {
|
|||||||
const url = new URL('message', this.config.url);
|
const url = new URL('message', this.config.url);
|
||||||
url.searchParams.set('token', this.config.token);
|
url.searchParams.set('token', this.config.token);
|
||||||
|
|
||||||
|
const controller = new AbortController();
|
||||||
|
const timeoutId = setTimeout(() => controller.abort(), 5000);
|
||||||
|
|
||||||
const response = await fetch(url.toString(), {
|
const response = await fetch(url.toString(), {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
@@ -27,8 +30,11 @@ export class GotifyNotificationService implements NotificationService {
|
|||||||
message,
|
message,
|
||||||
priority,
|
priority,
|
||||||
}),
|
}),
|
||||||
|
signal: controller.signal,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
clearTimeout(timeoutId);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const errorText = await response.text();
|
const errorText = await response.text();
|
||||||
console.error('Gotify notification failed:', {
|
console.error('Gotify notification failed:', {
|
||||||
|
|||||||
Reference in New Issue
Block a user