Skip to content

Commit

Permalink
Merge pull request #128 from Deep-Consulting-Solutions/task/cache-get…
Browse files Browse the repository at this point in the history
…AvailableSlots

Task/cache get available slots
GAMHnile authored Dec 12, 2024
2 parents 29460f4 + f80f6a6 commit ebfa3c4
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -7,3 +7,5 @@ plugins:
spec: "@yarnpkg/plugin-workspace-tools"

yarnPath: .yarn/releases/yarn-3.4.1.cjs


1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -105,6 +105,7 @@
"dependencies": {
"city-timezones": "^1.2.1",
"eslint": "^8.34.0",
"flatted": "^3.3.2",
"lucide-react": "^0.171.0",
"turbo": "^1.10.1"
},
7 changes: 4 additions & 3 deletions packages/trpc/server/routers/viewer/slots/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// eslint-disable-next-line no-restricted-imports
import { chunk, countBy } from "lodash";
import { v4 as uuid } from "uuid";
import { stringify, parse } from 'flatted';

import { getAggregatedAvailability } from "@calcom/core/getAggregatedAvailability";
import { getBusyTimesForLimitChecks } from "@calcom/core/getBusyTimes";
@@ -306,7 +307,7 @@ export async function getAvailableSlots({ input, ctx }: GetScheduleOptions, bypa
if((!input.rescheduleUid) && !bypassCacheResponse || ( !!input.rescheduleUid && process.env.AVAILABLE_SLOTS_CACHE_ON_RESCHEDULE === 'true' && !bypassCacheResponse)){
const response = await redis.get(cacheKey);
if(response){
const responseDetails: any = JSON.parse(response);
const responseDetails: any = parse(response);
return (responseDetails.response) as {
slots: Record<string, {
time: string;
@@ -673,7 +674,7 @@ export async function getAvailableSlots({ input, ctx }: GetScheduleOptions, bypa

if((!input.rescheduleUid) || ( !!input.rescheduleUid && process.env.AVAILABLE_SLOTS_CACHE_ON_RESCHEDULE === 'true')){
// store the response for a particular computation, it will then keep refreshing itself until it end date passes
await redis.set(cacheKey, JSON.stringify({input, ctx, response: {
await redis.set(cacheKey, stringify({input, ctx, response: {
slots: computedAvailableSlots,
}}))
}
@@ -723,7 +724,7 @@ const refreshAvailableSlotsCache = async () => {
batchedKeys.map(async (getAvailableSlotsCacheKey: any) => {
const dataToRefreshJSON = await redis.get(getAvailableSlotsCacheKey);
if(dataToRefreshJSON){
const dataToRefresh = (JSON.parse(dataToRefreshJSON)) as GetScheduleOptions & {response: any}
const dataToRefresh = (parse(dataToRefreshJSON)) as GetScheduleOptions & {response: any}
// check if end time has passed and remove the item from cache else, refresh it
// TODO_ESA: this logic may need to be modified to have a better cache clearing strategy
if(new Date() < new Date(dataToRefresh.input.endTime)){
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -15576,6 +15576,7 @@ __metadata:
city-timezones: ^1.2.1
dotenv-checker: ^1.1.5
eslint: ^8.34.0
flatted: ^3.3.2
husky: ^8.0.0
i18n-unused: ^0.13.0
jest-diff: ^29.5.0
@@ -20184,6 +20185,13 @@ __metadata:
languageName: node
linkType: hard

"flatted@npm:^3.3.2":
version: 3.3.2
resolution: "flatted@npm:3.3.2"
checksum: ac3c159742e01d0e860a861164bcfd35bb567ccbebb8a0dd041e61cf3c64a435b917dd1e7ed1c380c2ebca85735fb16644485ec33665bc6aafc3b316aa1eed44
languageName: node
linkType: hard

"flow-parser@npm:0.*":
version: 0.223.3
resolution: "flow-parser@npm:0.223.3"

0 comments on commit ebfa3c4

Please sign in to comment.