Agenda refactor

This commit is contained in:
alma 2026-01-15 17:27:43 +01:00
parent 533c42bff4
commit 510fbfc3e0

View File

@ -320,7 +320,24 @@ export default async function CalendarPage() {
}
// Clean up duplicate calendars for the same mailCredentialId
// Keep only the most recent one with syncEnabled=true, delete others
// NOTE: This is mainly for cleaning up OLD duplicates created before we fixed the cascade deletion
// New duplicates should not occur since we now delete calendars when mail accounts are deleted
// This cleanup is conservative: only processes if there are multiple ENABLED syncs for the same account
// Only run cleanup if there are actually multiple syncs to check (performance optimization)
const syncCountCheck = await prisma.calendarSync.count({
where: {
calendar: {
userId: session?.user?.id || ''
},
mailCredentialId: {
in: Array.from(allMailCredentialIds)
}
}
});
// Only run full cleanup if there are multiple syncs (likely duplicates)
if (syncCountCheck > allMailCredentialIds.size) {
const allSyncs = await prisma.calendarSync.findMany({
where: {
calendar: {
@ -423,6 +440,7 @@ export default async function CalendarPage() {
}
}
}
}
// Auto-sync Microsoft calendars if needed (background, don't block page load)
const microsoftSyncConfigs = await prisma.calendarSync.findMany({