perf: optimize DB queries, SSE polling, and client rendering
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 4m45s

- Fix resolveCollaborator N+1: replace full User table scan with findFirst
- Fix getAllUsersWithStats N+1: use groupBy instead of per-user count queries
- Cache getTeamMemberIdsForAdminTeams and isAdminOfUser with React.cache
- Increase SSE poll interval from 1s to 2s across all 5 subscribe routes
- Add cleanupOldEvents method to session-share-events for event table TTL
- Add React.memo to all card components (Swot, Motivator, Weather, WeeklyCheckIn, YearReview)
- Fix WeatherCard useEffect+setState lint error with idiomatic prop sync pattern
- Add optimizePackageImports for DnD libs and poweredByHeader:false in next.config
- Add inline theme script in layout.tsx to prevent dark mode FOUC
- Remove unused Next.js template SVGs from public/

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-25 14:04:58 +01:00
parent 6dfeab5eb8
commit c828ab1a48
21 changed files with 168 additions and 65 deletions

View File

@@ -48,6 +48,9 @@ type EventDelegate = {
orderBy: { createdAt: 'desc' };
select: { createdAt: true };
}) => Promise<{ createdAt: Date } | null>;
deleteMany: (args: {
where: { createdAt: { lt: Date } };
}) => Promise<unknown>;
};
type SessionDelegate = {
@@ -168,5 +171,13 @@ export function createShareAndEventHandlers<TEventType extends string>(
});
return event?.createdAt;
},
/** Delete events older than the given number of hours (default: 24h) */
async cleanupOldEvents(maxAgeHours = 24) {
const cutoff = new Date(Date.now() - maxAgeHours * 60 * 60 * 1000);
return eventModel.deleteMany({
where: { createdAt: { lt: cutoff } },
});
},
};
}