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:
parent
e4c1208b29
commit
59778d34fa
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "my-weekly-todo-list",
|
"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",
|
"description": "A web-based weekly task management application that organizes to-dos and calendar events in a single, intuitive weekly view",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@ -2944,7 +2944,7 @@ export default function WeeklyView() {
|
|||||||
};
|
};
|
||||||
}, [session]);
|
}, [session]);
|
||||||
|
|
||||||
// Periodic background calendar cache refresh (every 15 minutes)
|
// Periodic background calendar cache refresh (every 2 minutes)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!session) return;
|
if (!session) return;
|
||||||
const interval = setInterval(
|
const interval = setInterval(
|
||||||
@ -2974,11 +2974,24 @@ export default function WeeklyView() {
|
|||||||
console.error("[SYNC] Calendar sync error:", e);
|
console.error("[SYNC] Calendar sync error:", e);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
15 * 60 * 1000,
|
2 * 60 * 1000,
|
||||||
);
|
);
|
||||||
return () => clearInterval(interval);
|
return () => clearInterval(interval);
|
||||||
}, [session, fetchCalendarEvents]);
|
}, [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() {
|
async function fetchConnections() {
|
||||||
try {
|
try {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
import { prisma } from './prisma';
|
import { prisma } from './prisma';
|
||||||
import { getCalendarEvents, CalendarEvent, CalendarConnection } from './calendar-events';
|
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.
|
* Get the Monday (start of ISO week) for a given date.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user