fix: disregarding already booked spots or blocked calendar times#2029
fix: disregarding already booked spots or blocked calendar times#2029zomars merged 16 commits intocalcom:mainfrom
Conversation
|
@LouisHaftmann is attempting to deploy a commit to the cal Team on Vercel. A member of the Team first needs to authorize it. |
|
This pull request is being automatically deployed with Vercel (learn more). docs – ./apps/docs🔍 Inspect: https://vercel.com/cal/docs/3k2rWuuS5FKWw3skci5RvR8VhaJf [Deployment for ed8ee19 canceled] calendso – ./apps/web🔍 Inspect: https://vercel.com/cal/calendso/DCyWNY8VYBC2x7Yt7BC9SeBu2DTC |
alannnc
left a comment
There was a problem hiding this comment.
Awesome! It's working properly now
|
are you using any calendar integrations (google/apple/microsoft)? |
|
yea that's the problem, i'll look into it |
|
I just noticed that we aren't checking for conflicts before creating the booking, not even whether the time slot is out of bounds. Any reason for that? |
|
i believe this line is supposed create a unique seed for each time slot but why does it use const seed = `${users[0].username}:${dayjs(req.body.start).utc().format()}:${new Date().getTime()}`; |
You are entirely right about this; this is a bug that still exists and was a "hack" whilst integrating Daily to get it to work. (Not quite sure what broke, maybe @baileypumfleet remembers, or @lunchpaillola. The idea of this seed before then was to prevent conflicts on database level (which was disabled causing the bugs). When this seed works, it would create a unique seed for each slot, causing a P2002 on database level (unique constraint violation). Database was originally deemed to be the ideal place of doing this as any other location would cause race conditions in times of high traffic. Edit: It used to be: https://github.com/calcom/cal.com/blame/58de9209512c45e253ba3737311a0e21e0d1cf10/pages/api/book/event.ts#L252 |
|
Even with the old seed it wouldn't be 100% safe because it doesn't include any info about end time or time slot duration. Changing an event type's duration (eg: from 30min to 15min) would break this conflict check because a booking could be created without conflict error although it conflicts with the old booking. Example (event type duration: 30min):
|
|
In this commit I made it so it fetches all existing bookings for the user and event type and checks for conflicts (including integration and video busy times) before even trying to create a booking in the db. |
|
Yeah this is an improvement on the current broken logic, but does need further development. The event type duration isn't as much of a problem as the seed logic is intended to detect double bookings made at the same time, it's not meant to check freebusy - that happens before then. Reasons for future (Approving this in principle) development are:
Virtual calendar is a feature that will focus on improving this |
|
A seed like userId:eventTypeId:startTimewould probably work for now. It doesn't cover all edge cases but would atleast prevent simple double booking |
|
Prisma's @@unique constraint could also work |
once @zomars reviewed this PR, he can merge it |
|
Checking... |
| }); | ||
|
|
||
| const credentials = currentUser.credentials; | ||
| const calendarBusyTimes: EventBusyDate[] = await prisma.booking |
There was a problem hiding this comment.
Not a blocking issue but we should strive to rely on inferred types as much as possible.
zomars
left a comment
There was a problem hiding this comment.
This is great! Just left some minor comments in there 🙏🏽
|
|
||
| // @TODO: Find a better way to make test wait for full month change render to end | ||
| // so it can click up on the right day, also when resolve remove other todos | ||
| // Waiting for full month increment | ||
| await page.waitForTimeout(400); |
There was a problem hiding this comment.
I think this was removed by mistake. This is a temporal fix made by @alannnc so tests aren't randomly failing due to loading times.
There was a problem hiding this comment.
sry, removed this by accident
zomars
left a comment
There was a problem hiding this comment.
Pushed fixes to prevent further delays. Thank you for your contribution 🙏
It's been a while so I don't know if that hack is still relevant since I'm sure the code has changed a bit. But for some historical context the new date had to do with rebooking a time that had been previously canceled. Without the hack if you had canceled a time you wouldn't be able to rebook that time even if the slot had been canceled. Sounds like it's all sorted now though! |

What does this PR do?
Fixes double-booking issue
Fixes #1271, #1450
Type of change
How should this be tested?