refactor: reduce CalDAV sync to login and manual sync button only

- Remove auto-login sync in AuthGuard
- Remove 10s interval sync and syncAndReload in calendar tab
- Remove lazy syncOnce pattern in ChatService AI callbacks
- Remove CaldavService dependency from ChatService constructor
This commit is contained in:
2026-02-09 23:32:04 +01:00
parent 5a9485acfc
commit b9ffc6c908
4 changed files with 3 additions and 45 deletions

View File

@@ -17,7 +17,6 @@ import { Ionicons } from "@expo/vector-icons";
import { useThemeStore } from "../../stores/ThemeStore"; import { useThemeStore } from "../../stores/ThemeStore";
import BaseBackground from "../../components/BaseBackground"; import BaseBackground from "../../components/BaseBackground";
import { EventService } from "../../services"; import { EventService } from "../../services";
import { CaldavConfigService } from "../../services/CaldavConfigService";
import { useEventsStore } from "../../stores"; import { useEventsStore } from "../../stores";
import { useDropdownPosition } from "../../hooks/useDropdownPosition"; import { useDropdownPosition } from "../../hooks/useDropdownPosition";
@@ -108,25 +107,11 @@ const Calendar = () => {
} }
}, [monthIndex, currentYear, setEvents]); }, [monthIndex, currentYear, setEvents]);
// Sync CalDAV in background, then reload events // Load events from DB on focus
const syncAndReload = useCallback(async () => {
try {
await CaldavConfigService.sync();
await loadEvents();
} catch {
// Sync failed — not critical
}
}, [loadEvents]);
// Load events instantly on focus, then sync in background periodically
useFocusEffect( useFocusEffect(
useCallback(() => { useCallback(() => {
loadEvents(); loadEvents();
syncAndReload(); }, [loadEvents]),
const interval = setInterval(syncAndReload, 10_000);
return () => clearInterval(interval);
}, [loadEvents, syncAndReload]),
); );
// Re-open overlay after back navigation from editEvent // Re-open overlay after back navigation from editEvent

View File

@@ -62,11 +62,6 @@ export const AuthGuard = ({ children }: AuthGuardProps) => {
if (!useAuthStore.getState().isAuthenticated) return; if (!useAuthStore.getState().isAuthenticated) return;
await preloadAppData(); await preloadAppData();
setDataReady(true); setDataReady(true);
try {
await CaldavConfigService.sync();
} catch {
// No CalDAV config or sync failed — not critical
}
}; };
init(); init();
}, [loadStoredUser]); }, [loadStoredUser]);

View File

@@ -63,12 +63,7 @@ const aiProvider = new GPTAdapter();
const authService = new AuthService(userRepo); const authService = new AuthService(userRepo);
const eventService = new EventService(eventRepo); const eventService = new EventService(eventRepo);
const caldavService = new CaldavService(caldavRepo, eventService); const caldavService = new CaldavService(caldavRepo, eventService);
const chatService = new ChatService( const chatService = new ChatService(chatRepo, eventService, aiProvider);
chatRepo,
eventService,
aiProvider,
caldavService,
);
// Initialize controllers // Initialize controllers
const authController = new AuthController(authService); const authController = new AuthController(authService);

View File

@@ -14,7 +14,6 @@ import {
} from "@calchat/shared"; } from "@calchat/shared";
import { ChatRepository, AIProvider } from "./interfaces"; import { ChatRepository, AIProvider } from "./interfaces";
import { EventService } from "./EventService"; import { EventService } from "./EventService";
import { CaldavService } from "./CaldavService";
import { getWeeksOverview, getMonthOverview } from "../utils/eventFormatters"; import { getWeeksOverview, getMonthOverview } from "../utils/eventFormatters";
type TestResponse = { type TestResponse = {
@@ -543,7 +542,6 @@ export class ChatService {
private chatRepo: ChatRepository, private chatRepo: ChatRepository,
private eventService: EventService, private eventService: EventService,
private aiProvider: AIProvider, private aiProvider: AIProvider,
private caldavService: CaldavService,
) {} ) {}
async processMessage( async processMessage(
@@ -578,32 +576,17 @@ export class ChatService {
limit: 20, limit: 20,
}); });
// Lazy CalDAV sync: only sync once when the AI first accesses event data
let hasSynced = false;
const syncOnce = async () => {
if (hasSynced) return;
hasSynced = true;
try {
await this.caldavService.sync(userId);
} catch {
// CalDAV sync is not critical for AI responses
}
};
response = await this.aiProvider.processMessage(data.content, { response = await this.aiProvider.processMessage(data.content, {
userId, userId,
conversationHistory: history, conversationHistory: history,
currentDate: new Date(), currentDate: new Date(),
fetchEventsInRange: async (start, end) => { fetchEventsInRange: async (start, end) => {
await syncOnce();
return this.eventService.getByDateRange(userId, start, end); return this.eventService.getByDateRange(userId, start, end);
}, },
searchEvents: async (query) => { searchEvents: async (query) => {
await syncOnce();
return this.eventService.searchByTitle(userId, query); return this.eventService.searchByTitle(userId, query);
}, },
fetchEventById: async (eventId) => { fetchEventById: async (eventId) => {
await syncOnce();
return this.eventService.getById(eventId, userId); return this.eventService.getById(eventId, userId);
}, },
}); });