cal.com icon indicating copy to clipboard operation
cal.com copied to clipboard

Generate SSG Page used as cache for user's third-party calendar

Open roae opened this issue 3 years ago • 14 comments

What does this PR do?

  • Generate a SSG page used as cache for user`s third-party calendars by month, this page revalidates each second.
  • tRCP getSchedule endpoint change: now get the generated json file for the SSG page which is normally used by NextJS in the browser navigation to get the third-party calendar data

TODO

  • [x] Revalidate cache page when users connect/disconnect a calendar.
  • [x] Revalidate when users change the selected calendars.
  • [ ] Revalidate when the user adds or deletes an event directly in the connected calendars via webhooks.
  • [x] Add API endpoint to revalidates several months ahead.

Fixes #4535 /claim #4535

Note: On development environment the response time of getSchedule endpoint increases because NextJS compiles the cache page first. To notice the improvement you must run a production build.

Type of change

  • [ ] Bug fix (non-breaking change which fixes an issue)
  • [x] Chore (refactoring code, technical debt, workflow improvements)
  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [ ] This change requires a documentation update

Checklist

  • I haven't read the contributing guide
  • My code doesn't follow the style guidelines of this project
  • I haven't checked if my PR needs changes to the documentation
  • I haven't checked if my changes generate no new warnings
  • I haven't added tests that prove my fix is effective or that my feature works
  • I haven't checked if new and existing unit tests pass locally with my changes

roae avatar Jan 29 '23 05:01 roae

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
cal ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Feb 13, 2023 at 6:44PM (UTC)
1 Ignored Deployment
Name Status Preview Comments Updated
ui ⬜️ Ignored (Inspect) Visit Preview Feb 13, 2023 at 6:44PM (UTC)

vercel[bot] avatar Jan 29 '23 05:01 vercel[bot]

@roae is attempting to deploy a commit to the cal Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Jan 29 '23 05:01 vercel[bot]

is this related to the RFC for caching calendars or is this unrelated?

PeerRich avatar Feb 02 '23 19:02 PeerRich

is this related to the RFC for caching calendars or is this unrelated?

It is a different approach @PeerRich no need for a custom caldav server (at least not yet)

zomars avatar Feb 02 '23 19:02 zomars

@roae can you uncommit your yarn.lock? (take it from our main)

PeerRich avatar Feb 02 '23 19:02 PeerRich

@roae can you uncommit your yarn.lock? (take it from our main)

Done!

roae avatar Feb 02 '23 21:02 roae

lovely progress here

PeerRich avatar Feb 09 '23 20:02 PeerRich

Added a canary domain preview to test the difference So far getting a response time average of 1.8 seconds

image

zomars avatar Feb 09 '23 23:02 zomars

do you have a benchmark of before/after with same payload / connected calendars?

PeerRich avatar Feb 10 '23 10:02 PeerRich

do you have a benchmark of before/after with same payload / connected calendars?

Captura de pantalla 2023-02-10 a la(s) 1 28 50 p m

roae avatar Feb 10 '23 20:02 roae

HOLY SHIT 4s down to 240ms?!

PeerRich avatar Feb 10 '23 21:02 PeerRich

HOLY SHIT 4s down to 240ms?!

Of course it varies between calls but still pretty impressive 🙌🏽

zomars avatar Feb 10 '23 21:02 zomars

unfortunately there is a new skeleton loader that wasnt there on current prod

CleanShot.2023-02-10.at.22.28.19.mp4

Adding more context to this change. We discovered that if a slot got taken and refetched it didn't disappear in the UI due the use of our local state. But agreed that we can improve the UX to match the previous one.

zomars avatar Feb 10 '23 21:02 zomars

I'm like 70% sure you can return from an API endpoint in Next with infinite cache times and not have to do the empty page hack - I do this all the time - revalidate works on API endpoints

t3dotgg avatar Feb 11 '23 08:02 t3dotgg

I'm like 70% sure you can return from an API endpoint in Next with infinite cache times and not have to do the empty page hack - I do this all the time - revalidate works on API endpoints

Care to elaborate @t3dotgg ? Is this cache useful for every user or would it only work per browser/request?

zomars avatar Feb 13 '23 18:02 zomars

unfortunately there is a new skeleton loader that wasnt there on current prod

CleanShot.2023-02-10.at.22.28.19.mp4

Skeleton got fixed

https://www.loom.com/share/4351b946528349dd87e201aa98bbca32

zomars avatar Feb 13 '23 18:02 zomars

Merging for now. We can always follow up with further improvements. Talked to @roae and it seems like the next big thing to solve would be reducing bundle size.

image

zomars avatar Feb 13 '23 18:02 zomars

nice lets merge! should I or do you wanna click the magic green button

PeerRich avatar Feb 13 '23 18:02 PeerRich

whopsy wrong button clicky

PeerRich avatar Feb 13 '23 18:02 PeerRich

This Is Fine GIF

zomars avatar Feb 13 '23 18:02 zomars

Talked to @roae and it seems like the next big thing to solve would be reducing bundle size.

I searched the current main. There are a few cases where the entire lodash is being imported for no reason. Should be a very easy fix that instantly reduces bundle size.

image

Did this in another project the other day, before/after: image image

leventdeniz avatar Feb 21 '23 10:02 leventdeniz

i think we can get rid of lodash alltogether no? most of lodash is ECMA specs now anyway

PeerRich avatar Feb 21 '23 11:02 PeerRich