Agenda refactor
This commit is contained in:
parent
ab6b4326ed
commit
71e97b3d72
@ -410,10 +410,25 @@ export default async function CalendarPage() {
|
|||||||
: Infinity;
|
: Infinity;
|
||||||
|
|
||||||
// Sync if never synced, or if enough time has passed (use minimum of 1 min or configured frequency)
|
// Sync if never synced, or if enough time has passed (use minimum of 1 min or configured frequency)
|
||||||
const needsSync = !syncConfig.lastSyncAt ||
|
// Also sync if last sync had an error or if calendar has no events (might be a new setup)
|
||||||
minutesSinceLastSync >= Math.min(microsoftMinSyncInterval, syncConfig.syncFrequency);
|
const calendar = await prisma.calendar.findUnique({
|
||||||
|
where: { id: syncConfig.calendarId },
|
||||||
|
include: {
|
||||||
|
_count: {
|
||||||
|
select: { events: true }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
console.log(`[AGENDA] Microsoft sync config ${syncConfig.id}: lastSyncAt=${syncConfig.lastSyncAt}, minutesSinceLastSync=${minutesSinceLastSync.toFixed(1)}, needsSync=${needsSync}, syncFrequency=${syncConfig.syncFrequency}`);
|
const hasEvents = (calendar?._count?.events || 0) > 0;
|
||||||
|
const hasError = !!syncConfig.lastSyncError;
|
||||||
|
|
||||||
|
const needsSync = !syncConfig.lastSyncAt ||
|
||||||
|
minutesSinceLastSync >= Math.min(microsoftMinSyncInterval, syncConfig.syncFrequency) ||
|
||||||
|
hasError || // Force sync if there was an error
|
||||||
|
(!hasEvents && syncConfig.lastSyncAt); // Force sync if calendar has no events but was synced before
|
||||||
|
|
||||||
|
console.log(`[AGENDA] Microsoft sync config ${syncConfig.id}: lastSyncAt=${syncConfig.lastSyncAt}, minutesSinceLastSync=${minutesSinceLastSync.toFixed(1)}, needsSync=${needsSync}, syncFrequency=${syncConfig.syncFrequency}, hasEvents=${hasEvents}, hasError=${hasError}`);
|
||||||
|
|
||||||
if (needsSync) {
|
if (needsSync) {
|
||||||
console.log(`[AGENDA] Triggering background sync for Microsoft calendar ${syncConfig.id}`);
|
console.log(`[AGENDA] Triggering background sync for Microsoft calendar ${syncConfig.id}`);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user