Agenda refactor
This commit is contained in:
parent
533c42bff4
commit
510fbfc3e0
@ -320,7 +320,24 @@ export default async function CalendarPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clean up duplicate calendars for the same mailCredentialId
|
// 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({
|
const allSyncs = await prisma.calendarSync.findMany({
|
||||||
where: {
|
where: {
|
||||||
calendar: {
|
calendar: {
|
||||||
@ -423,6 +440,7 @@ export default async function CalendarPage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Auto-sync Microsoft calendars if needed (background, don't block page load)
|
// Auto-sync Microsoft calendars if needed (background, don't block page load)
|
||||||
const microsoftSyncConfigs = await prisma.calendarSync.findMany({
|
const microsoftSyncConfigs = await prisma.calendarSync.findMany({
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user