Skip to content

Commit

Permalink
Prevent timeouts when cache fails (calcom#7095)
Browse files Browse the repository at this point in the history
Return empty cache instead of failing

Keeping console errors
  • Loading branch information
zomars authored Feb 14, 2023
1 parent b6eca6e commit 8e2ece7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
29 changes: 22 additions & 7 deletions apps/web/pages/[user]/calendar-cache/[month].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,28 @@ export const getStaticProps: GetStaticProps<
dayjs(month, "YYYY-MM").isSame(dayjs(), "month") ? dayjs() : dayjs(month, "YYYY-MM")
).startOf("day");
const endDate = startDate.endOf("month");
const results = user?.credentials
? await getCachedResults(user?.credentials, startDate.format(), endDate.format(), user?.selectedCalendars)
: [];
return {
props: { results, date: new Date().toISOString() },
revalidate: 1,
};
try {
const results = user?.credentials
? await getCachedResults(
user?.credentials,
startDate.format(),
endDate.format(),
user?.selectedCalendars
)
: [];
return {
props: { results, date: new Date().toISOString() },
revalidate: 1,
};
} catch (error) {
let message = "Unknown error while fetching calendarƒ";
if (error instanceof Error) message = error.message;
console.error(error, message);
return {
props: { results: [], date: new Date().toISOString(), message },
revalidate: 1,
};
}
};

export const getStaticPaths: GetStaticPaths = () => {
Expand Down
2 changes: 1 addition & 1 deletion apps/web/pages/api/trpc/[trpc].ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default trpcNext.createNextApiHandler({
"viewer.public.session": `no-cache`,
"viewer.public.i18n": `no-cache`,
// Revalidation time here should be 1 second, per https://github.com/calcom/cal.com/pull/6823#issuecomment-1423215321
"viewer.public.slots.getSchedule": `max-age=0, s-maxage=1`,
"viewer.public.slots.getSchedule": `no-cache`, // FIXME
} as const;

// Find which element above is an exact match for this group of paths
Expand Down

0 comments on commit 8e2ece7

Please sign in to comment.