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:
@@ -63,12 +63,7 @@ const aiProvider = new GPTAdapter();
|
||||
const authService = new AuthService(userRepo);
|
||||
const eventService = new EventService(eventRepo);
|
||||
const caldavService = new CaldavService(caldavRepo, eventService);
|
||||
const chatService = new ChatService(
|
||||
chatRepo,
|
||||
eventService,
|
||||
aiProvider,
|
||||
caldavService,
|
||||
);
|
||||
const chatService = new ChatService(chatRepo, eventService, aiProvider);
|
||||
|
||||
// Initialize controllers
|
||||
const authController = new AuthController(authService);
|
||||
|
||||
@@ -14,7 +14,6 @@ import {
|
||||
} from "@calchat/shared";
|
||||
import { ChatRepository, AIProvider } from "./interfaces";
|
||||
import { EventService } from "./EventService";
|
||||
import { CaldavService } from "./CaldavService";
|
||||
import { getWeeksOverview, getMonthOverview } from "../utils/eventFormatters";
|
||||
|
||||
type TestResponse = {
|
||||
@@ -543,7 +542,6 @@ export class ChatService {
|
||||
private chatRepo: ChatRepository,
|
||||
private eventService: EventService,
|
||||
private aiProvider: AIProvider,
|
||||
private caldavService: CaldavService,
|
||||
) {}
|
||||
|
||||
async processMessage(
|
||||
@@ -578,32 +576,17 @@ export class ChatService {
|
||||
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, {
|
||||
userId,
|
||||
conversationHistory: history,
|
||||
currentDate: new Date(),
|
||||
fetchEventsInRange: async (start, end) => {
|
||||
await syncOnce();
|
||||
return this.eventService.getByDateRange(userId, start, end);
|
||||
},
|
||||
searchEvents: async (query) => {
|
||||
await syncOnce();
|
||||
return this.eventService.searchByTitle(userId, query);
|
||||
},
|
||||
fetchEventById: async (eventId) => {
|
||||
await syncOnce();
|
||||
return this.eventService.getById(eventId, userId);
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user