fix: deduplicate UIDs during iCal import to prevent mass failures #113

This commit is contained in:
Linus Rath
2026-03-30 15:06:28 +02:00
parent 1eebec292a
commit 0fb8b81acd
11 changed files with 30 additions and 11 deletions
+20 -1
View File
@@ -383,9 +383,28 @@ export const useCalendarStore = create<CalendarStore>()(
const realCalendarId = cal?.originalId || calendarId;
const targetAccountId = cal?.accountId;
// Deduplicate: skip events whose UIDs already exist on the server
// (Stalwart enforces UID uniqueness across all calendars)
let eventsToProcess = events;
try {
const allServerEvents = await client.getCalendarEvents(undefined, targetAccountId);
const existingUids = new Set<string>();
for (const e of allServerEvents) {
if (e.uid) existingUids.add(e.uid);
}
const before = eventsToProcess.length;
eventsToProcess = eventsToProcess.filter(e => !e.uid || !existingUids.has(e.uid));
const skipped = before - eventsToProcess.length;
if (skipped > 0) {
debug.log(`Import: skipped ${skipped} events with duplicate UIDs (already on server)`);
}
} catch (error) {
debug.warn('Could not fetch existing events for deduplication, proceeding without:', error);
}
// Prepare all events for batch creation
const prepared: Partial<CalendarEvent>[] = [];
for (const event of events) {
for (const event of eventsToProcess) {
const src = sanitizeOutgoingCalendarEventData(event as Partial<CalendarEvent>);
let cleanParticipants: Record<string, CalendarParticipant> | null = null;
if (src.participants) {