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 <noreply@anthropic.com>
This commit is contained in:
mARTin 2026-03-25 13:28:00 +01:00
parent e4c1208b29
commit 59778d34fa
3 changed files with 17 additions and 4 deletions

View File

@ -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": {

View File

@ -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);

View File

@ -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.