chore: Determine to serve cache high level (#24756)
* chore: Determine to serve cache high level * Fix invalid import * fix: Cache test
This commit is contained in:
1 parent
1e1298fdbc
commit
91063c41f8
4 files changed
+26
-27
No files matched your search
@@ -3,6 +3,7 @@ import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import type { IFeaturesRepository } from "@calcom/features/flags/features.repository.interface";
|
||||
|
||||
import { CacheService } from "./getShouldServeCache";
|
||||
import { CalendarSubscriptionService } from "@calcom/features/calendar-subscription/lib/CalendarSubscriptionService";
|
||||
|
||||
describe("CacheService.getShouldServeCache", () => {
|
||||
const mockFeaturesRepository: IFeaturesRepository = {
|
||||
@@ -57,7 +58,7 @@ describe("CacheService.getShouldServeCache", () => {
|
||||
const result = await cacheService.getShouldServeCache(undefined, 123);
|
||||
|
||||
expect(result).toBe(true);
|
||||
expect(mockFeaturesRepository.checkIfTeamHasFeature).toHaveBeenCalledWith(123, "calendar-cache-serve");
|
||||
expect(mockFeaturesRepository.checkIfTeamHasFeature).toHaveBeenCalledWith(123, CalendarSubscriptionService.CALENDAR_SUBSCRIPTION_CACHE_FEATURE);
|
||||
});
|
||||
|
||||
it("should check feature repository when teamId is provided and return false if feature is disabled", async () => {
|
||||
@@ -66,7 +67,7 @@ describe("CacheService.getShouldServeCache", () => {
|
||||
const result = await cacheService.getShouldServeCache(undefined, 456);
|
||||
|
||||
expect(result).toBe(false);
|
||||
expect(mockFeaturesRepository.checkIfTeamHasFeature).toHaveBeenCalledWith(456, "calendar-cache-serve");
|
||||
expect(mockFeaturesRepository.checkIfTeamHasFeature).toHaveBeenCalledWith(456, CalendarSubscriptionService.CALENDAR_SUBSCRIPTION_CACHE_FEATURE);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -86,7 +87,7 @@ describe("CacheService.getShouldServeCache", () => {
|
||||
const result = await cacheService.getShouldServeCache(undefined, 999);
|
||||
|
||||
expect(result).toBe(true);
|
||||
expect(mockFeaturesRepository.checkIfTeamHasFeature).toHaveBeenCalledWith(999, "calendar-cache-serve");
|
||||
expect(mockFeaturesRepository.checkIfTeamHasFeature).toHaveBeenCalledWith(999, CalendarSubscriptionService.CALENDAR_SUBSCRIPTION_CACHE_FEATURE);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { IFeaturesRepository } from "@calcom/features/flags/features.repository.interface";
|
||||
import { CalendarSubscriptionService } from "@calcom/features/calendar-subscription/lib/CalendarSubscriptionService";
|
||||
|
||||
export interface ICacheService {
|
||||
featuresRepository: IFeaturesRepository;
|
||||
@@ -10,6 +11,6 @@ export class CacheService {
|
||||
async getShouldServeCache(shouldServeCache?: boolean | undefined, teamId?: number) {
|
||||
if (typeof shouldServeCache === "boolean") return shouldServeCache;
|
||||
if (!teamId) return false;
|
||||
return await this.dependencies.featuresRepository.checkIfTeamHasFeature(teamId, "calendar-cache-serve");
|
||||
return await this.dependencies.featuresRepository.checkIfTeamHasFeature(teamId, CalendarSubscriptionService.CALENDAR_SUBSCRIPTION_CACHE_FEATURE);
|
||||
}
|
||||
}
|
||||
@@ -94,7 +94,7 @@ const getCalendarsEvents = async (
|
||||
|
||||
const calendarAndCredentialPairs = await Promise.all(
|
||||
calendarCredentials.map(async (credential) => {
|
||||
const calendar = await getCalendar(credential);
|
||||
const calendar = await getCalendar(credential, shouldServeCache);
|
||||
return [calendar, credential] as const;
|
||||
})
|
||||
);
|
||||
@@ -193,7 +193,7 @@ function getServerUrlFromCalendarExternalId(externalId: string): string | null {
|
||||
try {
|
||||
const url = new URL(externalId);
|
||||
return `${url.protocol}//${url.host}`;
|
||||
} catch (error) {
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -215,7 +215,7 @@ function getServerUrlFromCredential(credential: CredentialForCalendarService): s
|
||||
|
||||
const url = new URL(decryptedData.url);
|
||||
return `${url.protocol}//${url.host}`;
|
||||
} catch (error) {
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user