Fix ensure_google_calendar to fetch all calendars with pagination to avoid missing calendars on later pages

This commit is contained in:
root
2025-10-25 07:42:05 +00:00
parent b4c4bf0a9e
commit 62f57bb035

View File

@@ -167,9 +167,20 @@ async def ensure_google_calendar(service, employee_kuerzel, context=None):
try: try:
# Enforce rate limiting for calendar list fetch # Enforce rate limiting for calendar list fetch
await enforce_global_rate_limit(context) await enforce_global_rate_limit(context)
calendar_list = service.calendarList().list().execute()
# Fetch all calendars with pagination
all_calendars = []
page_token = None
while True:
calendar_list = service.calendarList().list(pageToken=page_token, maxResults=250).execute()
calendars = calendar_list.get('items', [])
all_calendars.extend(calendars)
page_token = calendar_list.get('nextPageToken')
if not page_token:
break
calendar_id = None calendar_id = None
for calendar in calendar_list.get('items', []): for calendar in all_calendars:
if calendar['summary'] == calendar_name: if calendar['summary'] == calendar_name:
calendar_id = calendar['id'] calendar_id = calendar['id']
break break