Skip to content

The open alternative to Salesforce, designed for AI.

Chunk calendar participant updates back under the 200 row limit (#25465)

neo7731f524faee213
diff --git a/packages/twenty-server/src/modules/calendar/calendar-event-participant-manager/services/calendar-event-participant.service.ts b/packages/twenty-server/src/modules/calendar/calendar-event-participant-manager/services/calendar-event-participant.service.ts
index b600c9ff457..489b46df973 100644
--- a/packages/twenty-server/src/modules/calendar/calendar-event-participant-manager/services/calendar-event-participant.service.ts
+++ b/packages/twenty-server/src/modules/calendar/calendar-event-participant-manager/services/calendar-event-participant.service.ts
@@ -63,10 +63,11 @@ export class CalendarEventParticipantService {
});
}
- if (operations.participantsToUpdate.length > 0) {
- await calendarEventParticipantRepository.updateMany(
- operations.participantsToUpdate,
- );
+ for (const participantsChunk of chunk(
+ operations.participantsToUpdate,
+ CALENDAR_EVENT_PARTICIPANT_CHUNK_SIZE,
+ )) {
+ await calendarEventParticipantRepository.updateMany(participantsChunk);
}
for (const participantsChunk of chunk(
diff --git a/packages/twenty-server/test/integration/google/calendar/event-save-operations.integration-spec.ts b/packages/twenty-server/test/integration/google/calendar/event-save-operations.integration-spec.ts
index 2f7f547b406..926534d2c30 100644
--- a/packages/twenty-server/test/integration/google/calendar/event-save-operations.integration-spec.ts
+++ b/packages/twenty-server/test/integration/google/calendar/event-save-operations.integration-spec.ts
@@ -110,6 +110,23 @@ describe('Calendar event save operations (integration)', () => {
return Number(rows[0].count);
};
+ const countParticipantsByHandleSuffixAndDisplayName = async (
+ handleSuffix: string,
+ displayName: string,
+ ): Promise<number> => {
+ const rows: { count: string }[] =
+ await getCoreRepository<CalendarChannelEntity>(
+ CalendarChannelEntity,
+ ).manager.query(
+ `SELECT count(*) AS count FROM "${getWorkspaceSchemaName(
+ SEED_APPLE_WORKSPACE_ID,
+ )}"."calendarEventParticipant" WHERE handle LIKE $1 AND "displayName" = $2`,
+ [`%${handleSuffix}`, displayName],
+ );
+
+ return Number(rows[0].count);
+ };
+
beforeAll(async () => {
channel = await connectMessagingAccount({
provider: ConnectedAccountProvider.GOOGLE,
@@ -328,6 +345,44 @@ describe('Calendar event save operations (integration)', () => {
expect(await countParticipantsByHandleSuffix(attendeeSuffix)).toBe(300);
}, 300000);
+ it('should update every participant when a re-import spans more than one update chunk', async () => {
+ const titlePrefix = `Calendar event ${randomUUID()}`;
+ const eventIdSuffix = randomUUID();
+ const attendeeSuffix = `rechunked-${randomUUID()}@acme.com`;
+
+ const buildEvents = (displayName: string): calendar_v3.Schema$Event[] =>
+ Array.from({ length: 100 }, (_unused, eventIndex) =>
+ googleCalendarEvent({
+ id: `google-calendar-event-${eventIndex}-${eventIdSuffix}`,
+ summary: `${titlePrefix} ${eventIndex}`,
+ attendees: [
+ { email: `a-${eventIndex}-${attendeeSuffix}`, displayName },
+ { email: `b-${eventIndex}-${attendeeSuffix}`, displayName },
+ { email: `c-${eventIndex}-${attendeeSuffix}`, displayName },
+ ],
+ }),
+ );
+
+ await importEvents(buildEvents('Before'));
+
+ expect(
+ await countParticipantsByHandleSuffixAndDisplayName(
+ attendeeSuffix,
+ 'Before',
+ ),
+ ).toBe(300);
+
+ await importEvents(buildEvents('After'));
+
+ expect(await countParticipantsByHandleSuffix(attendeeSuffix)).toBe(300);
+ expect(
+ await countParticipantsByHandleSuffixAndDisplayName(
+ attendeeSuffix,
+ 'After',
+ ),
+ ).toBe(300);
+ }, 300000);
+
it('should update exactly one row and leave the other untouched when two participants share a handle on the same event', async () => {
const eventExternalId = `google-calendar-event-${randomUUID()}`;
const title = `Calendar event ${randomUUID()}`;