Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use FreeBusy for schedule availability #707

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

MelissaAutumn
Copy link
Member

@MelissaAutumn MelissaAutumn commented Oct 2, 2024

Fixes #662

Requesting caldav testers from: @devmount

This uses the freebusy api for Google and tries to use the freebusy api for CalDav. If the CalDav request fails it will use the old way of querying all of the events. This might give differing results since we can't calculate busyness based on attendance for caldav with the querying events method.

I need to cover the error conditions on the google side, and maybe look into re-architecture how the connectors work (Maybe steal how caldav has principal calendars and group them like that, but dunno yet.) And also add tests.

Why do we want to use this api instead of just calculating the availability based on the list of events? Because it's faster, and we can batch up the requests on the Google side for a significant speed up.

Caldav Ref:
https://caldav.readthedocs.io/en/latest/caldav/objects.html#caldav.objects.Calendar.freebusy_request

ICalendar Object:
https://icalendar.readthedocs.io/en/latest/api.html#icalendar.cal.FreeBusy

Google API Ref:
https://developers.google.com/calendar/api/v3/reference/freebusy/query

@MelissaAutumn MelissaAutumn self-assigned this Oct 2, 2024
Copy link
Collaborator

@devmount devmount left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First of all: The implementation works. I tested this with my Google calendar and with a custom Nextcloud CalDAV calendar. The results are surprising. Numbers in milliseconds. Measured waiting time on the schedule/public/availability call on page reload without cache. Averaged over 15 measurements each.

CalDAV freebusy CalDAV legacy Google freebusy Google legacy
915 61 447 68

The freebusy implementation is 93% slower for CalDAV and 85% slower for Google on my end. I feel I might have been made a mistake somewhere? Maybe this is depending on the event count in the availability timeframe? I have around 30 events in the requested time frame on each calendar.

I'm happy to do more testing if we need it.

@MelissaAutumn
Copy link
Member Author

Oh the old method caches for 15 minutes after the first load. Try removing the redis url from env 😄

@devmount
Copy link
Collaborator

Hahaha well, this is a bit emparrassing. I mistook the @limiter rule (which I commented out) on the endpoint for caching instead of rate limiting 🙈 Totally my bad 😂 I took the measurements for the legacy cases again, this time without redis 😅 But turns out the freebusy API doesn't have any significant effect not on Google nor on CalDAV on my end:

CalDAV freebusy CalDAV legacy Google freebusy Google legacy
915 918 447 451

I'm using a Nextcloud CalDAV calendar with around 30 events per month. Happy to do more testing if needed!

@MelissaAutumn
Copy link
Member Author

Hahaha well, this is a bit emparrassing. I mistook the @limiter rule (which I commented out) on the endpoint for caching instead of rate limiting 🙈 Totally my bad 😂 I took the measurements for the legacy cases again, this time without redis 😅 But turns out the freebusy API doesn't have any significant effect not on Google nor on CalDAV on my end:
CalDAV freebusy CalDAV legacy Google freebusy Google legacy
915 918 447 451

I'm using a Nextcloud CalDAV calendar with around 30 events per month. Happy to do more testing if needed!

How many calendars are you testing? The efficiency gain here is batching calendars together for availability. (Which I found with 4 google calendars)

And no worries, we should probably add a decorator for caching at route level sometime soon

@devmount
Copy link
Collaborator

One calendar each. I'll repeat the tests with more calendars then! Does it matter, if CalDAV calendars are from the same principal?

@MelissaAutumn
Copy link
Member Author

MelissaAutumn commented Oct 11, 2024

One calendar each. I'll repeat the tests with more calendars then! Does it matter, if CalDAV calendars are from the same principal?

Yeah they have to be from the same user/pass/url in order for that to work, although I don't think batched CalDAV calendars are supported yet. (They should be with a little extra work once the CalDAV PR is merged) The main issue was that we're calling each calendar individually to get their events and then we calculate the busy time ourselves. This should basically tells the server to do this for us.

@devmount
Copy link
Collaborator

I repeated CalDAV tests with 5 separate CalDAV calendars (from the same domain) and ~20 events in the requested time frame per calendar. This is the result:

CalDAV freebusy CalDAV legacy
5502 6135

So, there is an improvement of ca. 630ms in this scenario, which is good. We might gain more if we support batched CalDAV calendars though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use FreeBusy API to generate scheduling time
2 participants