From 59778d34fa26af148d23f560377b83b663a5bca9 Mon Sep 17 00:00:00 2001 From: mARTin Date: Wed, 25 Mar 2026 13:28:00 +0100 Subject: [PATCH] fix: faster calendar sync - 2min interval, sync on tab focus - Reduced cache stale threshold from 15 minutes to 2 minutes - Reduced background sync polling from 15 minutes to 2 minutes - Added visibilitychange listener: syncs calendars and tasks when the user switches back to the tab (catches external edits in Apple Calendar, Google Calendar, etc.) v1.74.7 Co-Authored-By: Claude Opus 4.6 --- package.json | 2 +- src/components/WeeklyView.tsx | 17 +++++++++++++++-- src/lib/calendar-cache.ts | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index b09eca1..7432aa7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "my-weekly-todo-list", - "version": "1.74.6", + "version": "1.74.7", "description": "A web-based weekly task management application that organizes to-dos and calendar events in a single, intuitive weekly view", "main": "index.js", "scripts": { diff --git a/src/components/WeeklyView.tsx b/src/components/WeeklyView.tsx index 4351399..e052c34 100644 --- a/src/components/WeeklyView.tsx +++ b/src/components/WeeklyView.tsx @@ -2944,7 +2944,7 @@ export default function WeeklyView() { }; }, [session]); - // Periodic background calendar cache refresh (every 15 minutes) + // Periodic background calendar cache refresh (every 2 minutes) useEffect(() => { if (!session) return; const interval = setInterval( @@ -2974,11 +2974,24 @@ export default function WeeklyView() { console.error("[SYNC] Calendar sync error:", e); } }, - 15 * 60 * 1000, + 2 * 60 * 1000, ); return () => clearInterval(interval); }, [session, fetchCalendarEvents]); + // Sync when tab regains focus (catches external changes in other apps) + useEffect(() => { + if (!session) return; + const handleVisibility = () => { + if (!document.hidden) { + fetchCalendarEvents(); + fetchTasks(); + } + }; + document.addEventListener('visibilitychange', handleVisibility); + return () => document.removeEventListener('visibilitychange', handleVisibility); + }, [session, fetchCalendarEvents]); + async function fetchConnections() { try { setIsLoading(true); diff --git a/src/lib/calendar-cache.ts b/src/lib/calendar-cache.ts index cda732c..e5d8b0a 100644 --- a/src/lib/calendar-cache.ts +++ b/src/lib/calendar-cache.ts @@ -4,7 +4,7 @@ import { prisma } from './prisma'; import { getCalendarEvents, CalendarEvent, CalendarConnection } from './calendar-events'; -const STALE_THRESHOLD_MS = 15 * 60 * 1000; // 15 minutes — reduce API calls to providers +const STALE_THRESHOLD_MS = 2 * 60 * 1000; // 2 minutes — keep in sync with external changes /** * Get the Monday (start of ISO week) for a given date.