perf(realtime+data): implement perf-data-optimization and perf-realtime-scale
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 3m33s
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 3m33s
## perf-data-optimization - Add @@index([name]) on User model (migration) - Add WEATHER_HISTORY_LIMIT=90 constant, apply take/orderBy on weather history queries - Replace deep includes with explicit select on all 6 list service queries - Add unstable_cache layer with revalidateTag on all list service functions - Add cache-tags.ts helpers (sessionTag, sessionsListTag, userStatsTag) - Invalidate sessionsListTag in all create/delete Server Actions ## perf-realtime-scale - Create src/lib/broadcast.ts: generic createBroadcaster factory with shared polling (one interval per active session, starts on first subscriber, stops on last) - Migrate all 6 SSE routes to use createBroadcaster — removes per-connection setInterval - Add broadcastToXxx() calls in all Server Actions after mutations for immediate push - Add SESSIONS_PAGE_SIZE=20, pagination on sessions page with loadMoreSessions action - Add "Charger plus" button with loading state and "X sur Y" counter in WorkshopTabs ## Tests - Add 19 unit tests for broadcast.ts (polling lifecycle, userId filtering, formatEvent, error resilience, session isolation) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
'use server';
|
||||
|
||||
import { revalidatePath } from 'next/cache';
|
||||
import { revalidatePath, revalidateTag } from 'next/cache';
|
||||
import { auth } from '@/lib/auth';
|
||||
import * as weeklyCheckInService from '@/services/weekly-checkin';
|
||||
import { sessionsListTag } from '@/lib/cache-tags';
|
||||
import { broadcastToWeeklyCheckInSession } from '@/app/api/weekly-checkin/[id]/subscribe/route';
|
||||
import type { WeeklyCheckInCategory, Emotion } from '@prisma/client';
|
||||
|
||||
// ============================================
|
||||
@@ -36,6 +38,7 @@ export async function createWeeklyCheckInSession(data: {
|
||||
}
|
||||
revalidatePath('/weekly-checkin');
|
||||
revalidatePath('/sessions');
|
||||
revalidateTag(sessionsListTag(session.user.id), 'default');
|
||||
return { success: true, data: weeklyCheckInSession };
|
||||
} catch (error) {
|
||||
console.error('Error creating weekly check-in session:', error);
|
||||
@@ -63,9 +66,11 @@ export async function updateWeeklyCheckInSession(
|
||||
data
|
||||
);
|
||||
|
||||
broadcastToWeeklyCheckInSession(sessionId, { type: 'SESSION_UPDATED' });
|
||||
revalidatePath(`/weekly-checkin/${sessionId}`);
|
||||
revalidatePath('/weekly-checkin');
|
||||
revalidatePath('/sessions');
|
||||
revalidateTag(sessionsListTag(authSession.user.id), 'default');
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
console.error('Error updating weekly check-in session:', error);
|
||||
@@ -83,6 +88,7 @@ export async function deleteWeeklyCheckInSession(sessionId: string) {
|
||||
await weeklyCheckInService.deleteWeeklyCheckInSession(sessionId, authSession.user.id);
|
||||
revalidatePath('/weekly-checkin');
|
||||
revalidatePath('/sessions');
|
||||
revalidateTag(sessionsListTag(authSession.user.id), 'default');
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
console.error('Error deleting weekly check-in session:', error);
|
||||
@@ -128,6 +134,7 @@ export async function createWeeklyCheckInItem(
|
||||
}
|
||||
);
|
||||
|
||||
broadcastToWeeklyCheckInSession(sessionId, { type: 'ITEM_CREATED' });
|
||||
revalidatePath(`/weekly-checkin/${sessionId}`);
|
||||
return { success: true, data: item };
|
||||
} catch (error) {
|
||||
@@ -169,6 +176,7 @@ export async function updateWeeklyCheckInItem(
|
||||
}
|
||||
);
|
||||
|
||||
broadcastToWeeklyCheckInSession(sessionId, { type: 'ITEM_UPDATED' });
|
||||
revalidatePath(`/weekly-checkin/${sessionId}`);
|
||||
return { success: true, data: item };
|
||||
} catch (error) {
|
||||
@@ -203,6 +211,7 @@ export async function deleteWeeklyCheckInItem(itemId: string, sessionId: string)
|
||||
{ itemId }
|
||||
);
|
||||
|
||||
broadcastToWeeklyCheckInSession(sessionId, { type: 'ITEM_DELETED' });
|
||||
revalidatePath(`/weekly-checkin/${sessionId}`);
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
@@ -246,6 +255,7 @@ export async function moveWeeklyCheckInItem(
|
||||
}
|
||||
);
|
||||
|
||||
broadcastToWeeklyCheckInSession(sessionId, { type: 'ITEM_MOVED' });
|
||||
revalidatePath(`/weekly-checkin/${sessionId}`);
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
@@ -284,6 +294,7 @@ export async function reorderWeeklyCheckInItems(
|
||||
{ category, itemIds }
|
||||
);
|
||||
|
||||
broadcastToWeeklyCheckInSession(sessionId, { type: 'ITEMS_REORDERED' });
|
||||
revalidatePath(`/weekly-checkin/${sessionId}`);
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user