refactor: Remove all code related to the old cache system (#25284)
* chore: Remove all code related to the old cache system * Removed some redundant tests, some type fixes * Further type fixes * More type fixes re. tests * Next iteration, couple of fixes remaining * Remove cache from CredentialActionsDropdown * Fix tests by mocking credential, instead of db queries * Remove Cache DI wiring from v2 * Make sure apiv2 build passes * Remove another cache cron * Remove old tokens for calendar-cache v1
This commit is contained in:
1 parent
d1184f65e2
commit
ae7fd0cae2
45 files changed
+58
-2765
No files matched your search
@@ -5,7 +5,6 @@ import { NextResponse } from "next/server";
|
||||
import { z } from "zod";
|
||||
|
||||
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
||||
import { CalendarCache } from "@calcom/features/calendar-cache/calendar-cache";
|
||||
import {
|
||||
getCalendarCredentials,
|
||||
getConnectedCalendars,
|
||||
@@ -92,15 +91,9 @@ async function deleteHandler(req: NextRequest) {
|
||||
const user = await authMiddleware();
|
||||
const searchParams = Object.fromEntries(req.nextUrl.searchParams.entries());
|
||||
|
||||
const { integration, externalId, credentialId, eventTypeId } =
|
||||
const { integration, externalId, eventTypeId } =
|
||||
selectedCalendarSelectSchema.parse(searchParams);
|
||||
|
||||
const calendarCacheRepository = await CalendarCache.initFromCredentialId(credentialId);
|
||||
await calendarCacheRepository.unwatchCalendar({
|
||||
calendarId: externalId,
|
||||
eventTypeIds: [eventTypeId ?? null],
|
||||
});
|
||||
|
||||
await SelectedCalendarRepository.delete({
|
||||
where: {
|
||||
userId: user.id,
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
import { defaultResponderForAppDir } from "app/api/defaultResponderForAppDir";
|
||||
import type { NextRequest } from "next/server";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
async function postHandler(request: NextRequest) {
|
||||
const apiKey = request.headers.get("authorization") || request.nextUrl.searchParams.get("apiKey");
|
||||
|
||||
if (![process.env.CRON_API_KEY, `Bearer ${process.env.CRON_SECRET}`].includes(`${apiKey}`)) {
|
||||
return NextResponse.json({ message: "Not authenticated" }, { status: 401 });
|
||||
}
|
||||
|
||||
const deleted = await prisma.calendarCache.deleteMany({
|
||||
where: {
|
||||
// Delete all cache entries that expired before now
|
||||
expiresAt: {
|
||||
lte: new Date(Date.now()),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json({ ok: true, count: deleted.count });
|
||||
}
|
||||
|
||||
export const POST = defaultResponderForAppDir(postHandler);
|
||||
@@ -24,7 +24,6 @@ try {
|
||||
async function () {
|
||||
await Promise.allSettled([
|
||||
fetchCron("/cron/calendar-subscriptions"),
|
||||
// fetchCron("/calendar-cache/cron"),
|
||||
// fetchCron("/cron/calVideoNoShowWebhookTriggers"),
|
||||
fetchCron("/tasks/cron"),
|
||||
]);
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
export { default } from "@calcom/features/calendar-cache/api/cron";
|
||||
@@ -2,8 +2,6 @@ import { expect } from "@playwright/test";
|
||||
import type { Page, Browser, Route, Response } from "@playwright/test";
|
||||
import type { z } from "zod";
|
||||
|
||||
import { CalendarCacheRepository } from "@calcom/features/calendar-cache/calendar-cache.repository";
|
||||
import { getTimeMin, getTimeMax } from "@calcom/features/calendar-cache/lib/datesForCache";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import type { Team, EventType, User } from "@calcom/prisma/client";
|
||||
import { MembershipRole, SchedulingType } from "@calcom/prisma/enums";
|
||||
@@ -65,10 +63,7 @@ test.describe("Booking Race Condition Prevention", () => {
|
||||
await setupGoogleCalendarCredentials(teamMembers);
|
||||
await createIdenticalBookingHistories(teamMembers, teamEvent.id);
|
||||
|
||||
const { selectedDate, selectedDateISO } = await getDynamicBookingDate(page, org, team, teamEvent);
|
||||
|
||||
const { targetHost, calendarCacheHits } = await setupCalendarCache(teamMembers, selectedDateISO);
|
||||
await enableCalendarCacheFeatures(team.id);
|
||||
const { selectedDate } = await getDynamicBookingDate(page, org, team, teamEvent);
|
||||
|
||||
const { firstResponse, secondResponse } = await performConcurrentBookings(
|
||||
page,
|
||||
@@ -226,82 +221,6 @@ async function getDynamicBookingDate(
|
||||
};
|
||||
}
|
||||
|
||||
async function setupCalendarCache(teamMembers: User[], selectedDateISO: string) {
|
||||
const cacheTimeRange = {
|
||||
timeMin: getTimeMin(selectedDateISO),
|
||||
timeMax: getTimeMax(selectedDateISO),
|
||||
};
|
||||
|
||||
const credentials = await prisma.credential.findMany({
|
||||
where: {
|
||||
userId: { in: teamMembers.map((m) => m.id) },
|
||||
type: "google_calendar",
|
||||
},
|
||||
});
|
||||
|
||||
const calendarCacheRepo = new CalendarCacheRepository(null);
|
||||
const targetHost = teamMembers[0];
|
||||
const calendarCacheHits: string[] = [];
|
||||
|
||||
for (let i = 0; i < credentials.length; i++) {
|
||||
const credential = credentials[i];
|
||||
const member = teamMembers[i];
|
||||
|
||||
const cacheArgs = {
|
||||
timeMin: cacheTimeRange.timeMin,
|
||||
timeMax: cacheTimeRange.timeMax,
|
||||
items: [{ id: member.email! }],
|
||||
};
|
||||
|
||||
const availabilityData = {
|
||||
kind: "calendar#freeBusy",
|
||||
calendars: {
|
||||
[member.email!]: {
|
||||
busy:
|
||||
member.id === targetHost.id
|
||||
? []
|
||||
: [
|
||||
{
|
||||
start: `${selectedDateISO.slice(0, 10)}T08:00:00.000Z`,
|
||||
end: `${selectedDateISO.slice(0, 10)}T08:30:00.000Z`,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
await calendarCacheRepo.upsertCachedAvailability({
|
||||
credentialId: credential.id,
|
||||
userId: member.id,
|
||||
args: cacheArgs,
|
||||
value: availabilityData,
|
||||
});
|
||||
|
||||
calendarCacheHits.push(`${member.email}-${credential.id}`);
|
||||
}
|
||||
|
||||
return { targetHost, calendarCacheHits };
|
||||
}
|
||||
|
||||
async function enableCalendarCacheFeatures(teamId: number) {
|
||||
await prisma.teamFeatures.createMany({
|
||||
data: [
|
||||
{
|
||||
teamId,
|
||||
featureId: "calendar-cache",
|
||||
assignedAt: new Date(),
|
||||
assignedBy: "race-condition-test",
|
||||
},
|
||||
{
|
||||
teamId,
|
||||
featureId: "calendar-cache-serve",
|
||||
assignedAt: new Date(),
|
||||
assignedBy: "race-condition-test",
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
async function mockGoogleCalendarAPI(page: Page, selectedDateISO: string) {
|
||||
const busyStart = `${selectedDateISO.slice(0, 10)}T08:00:00.000Z`;
|
||||
const busyEnd = `${selectedDateISO.slice(0, 10)}T09:00:00.000Z`;
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
{
|
||||
"crons": [
|
||||
{
|
||||
"path": "/api/cron/calendar-cache-cleanup",
|
||||
"schedule": "0 5 * * *"
|
||||
},
|
||||
{
|
||||
"path": "/api/cron/calendar-subscriptions",
|
||||
"schedule": "*/5 * * * *"
|
||||
@@ -20,10 +16,6 @@
|
||||
"path": "/api/tasks/cron",
|
||||
"schedule": "* * * * *"
|
||||
},
|
||||
{
|
||||
"path": "/api/calendar-cache/cron",
|
||||
"schedule": "* * * * *"
|
||||
},
|
||||
{
|
||||
"path": "/api/tasks/cleanup",
|
||||
"schedule": "0 0 * * *"
|
||||
|
||||
Reference in new issue
Block a user