Skip to content

Buffer limits fix#5248

Merged
kodiakhq[bot] merged 9 commits intomainfrom
bug/buffer_limits
Nov 2, 2022
Merged

Buffer limits fix#5248
kodiakhq[bot] merged 9 commits intomainfrom
bug/buffer_limits

Conversation

@sean-brydon
Copy link
Copy Markdown
Member

This PR fixes the buffer limit logic for before + after limits.

I will record a Loom for this tomorrow if needed. Please checkout and test this branch on preview to ensure the correct behaviour is indented.

@vercel
Copy link
Copy Markdown

vercel Bot commented Oct 27, 2022

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

Name Status Preview Updated
cal ✅ Ready (Inspect) Visit Preview Nov 2, 2022 at 9:35AM (UTC)

Copy link
Copy Markdown
Member

@CarinaWolli CarinaWolli left a comment

Choose a reason for hiding this comment

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

I did not fully follow the conversation about buffers but I think there is something still not right yet 🤔 I have a before buffer of 15 minutes, so I don't think I should be able to make my bookings like that:

Screenshot 2022-10-28 at 15 38 42

Comment thread packages/core/getBusyTimes.ts
Comment thread packages/core/getBusyTimes.ts
Comment thread packages/core/getUserAvailability.ts
Comment thread apps/web/test/lib/slots.test.ts
Comment thread packages/core/getUserAvailability.ts Outdated
end: dayjs(a.end)
.add(currentUser.bufferTime + (afterEventBuffer || 0), "minute")
start: dayjs(a.start)
.subtract(afterEventBuffer || 0, "minutes")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we need to add the beforeEventBuffer here too. I was able to book this with a beforeEventBuffer of 15 minutes:
Screenshot 2022-10-28 at 15 33 52

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I will investigate this on Monday :) Although this is different behaviour from what myself and @Jaibles have experienced.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Confirmed this is indeed a bug @CarinaWolli - nice spot. It happens when you book 2:30 before you book 2:15. beforeBuffer needs to be taken into account in the busyTime

@ciaranha
Copy link
Copy Markdown
Member

ciaranha commented Oct 31, 2022

I did not fully follow the conversation about buffers but I think there is something still not right yet 🤔 I have a before buffer of 15 minutes, so I don't think I should be able to make my bookings like that:

Yea the conversation was largely about ensuring you cannot end up with back to back meetings (and preventing it actually requires adding a buffer before and after even if you've just set before)

@alishaz-polymath
Copy link
Copy Markdown
Member

Pretty sure in this logic we can still end up with back to back bookings by simply booking through an event type which doesn't have buffer. @sean-brydon @Jaibles

Copy link
Copy Markdown
Member

@CarinaWolli CarinaWolli left a comment

Choose a reason for hiding this comment

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

I left you one comment. However, I found another bug that has nothing to do with your PR that makes it unable to even test this. I tried to book 2 different event types (one has only a before buffer and one has before and after), but I realized that busyTimes only includes the bookings from the event type that is currently booked. I think we need to remove the eventTypeId when querying the busyTimes, so we also include all other bookings from different event types in the availabilities

Comment thread packages/core/getBusyTimes.ts Outdated
bookings.map(({ startTime, endTime, title, id, eventType }) => ({
start: startTime,
end: dayjs(endTime)
.add((eventType?.afterEventBuffer || afterEventBuffer || 0) + (beforeEventBuffer || 0), "minute")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we only need to add eventType.afterEventBuffer here. If there is none, we don't need to add the afterEventBuffer from the booking.

.findMany({
where: {
userId,
eventTypeId,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Nice spot @CarinaWolli - Looks like we were only getting busy events for this particular event type and not all event types. Potentially allowing a double booking (same time) as each other


MockDate.set("2021-06-20T11:59:59Z");

it("can fit 24 hourly slots for an empty day", async () => {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Remove tests on code that isn't used in product anymore

start: startTime,
bookings.map(({ startTime, endTime, title, id, eventType }) => ({
start: dayjs(startTime)
.subtract((eventType?.beforeEventBuffer || 0) + (afterEventBuffer || 0), "minute")
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks @CarinaWolli for this fix :)

Always subtract the beforeEventBuffer for this specific booking eventType - then add afterEventBuffer for the buffer you are trying to book.

Preventing different event types from having a clash

busyTimes.push(
...calendarBusyTimes.map((value) => ({
...value,
end: dayjs(value.end)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Always add beforeEventBuffer to the end time so we get separation on calendar events

Without this we could book a meeting straight after a normal calendar event.

.add(beforeEventBuffer || 0, "minute")
.toDate(),
start: dayjs(value.start)
.subtract(afterEventBuffer || 0, "minute")
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Always subtract afterEventBuffer if it exists

const bufferedBusyTimes: EventBusyDetails[] = busyTimes.map((a) => ({
...a,
start: dayjs(a.start).subtract(currentUser.bufferTime, "minute").toISOString(),
end: dayjs(a.end)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This logic is handled in getBusyTimes now as bookings/calendar events require different logic

currentSeats,
}: {
time: Dayjs;
busy: (TimeRange | { start: string; end: string } | EventBusyDate)[];
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

These types just simply are EventBusyDate - not sure why we replicated this


return busy.every((busyTime) => {
const startTime = dayjs.utc(busyTime.start).subtract(beforeBufferTime, "minutes").utc();
const startTime = dayjs.utc(busyTime.start).utc();
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Handled in getBusyTimes

Copy link
Copy Markdown
Member

@alishaz-polymath alishaz-polymath left a comment

Choose a reason for hiding this comment

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

Looks good to me. Buffer specific testing went well
Awesome job @sean-brydon

Copy link
Copy Markdown
Member

@CarinaWolli CarinaWolli left a comment

Choose a reason for hiding this comment

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

Tested and works as expected 👏🏻

@sean-brydon sean-brydon added ♻️ autoupdate tells kodiak to keep this branch up-to-date automerge labels Nov 2, 2022
@kodiakhq kodiakhq Bot merged commit f34d6e3 into main Nov 2, 2022
@kodiakhq kodiakhq Bot deleted the bug/buffer_limits branch November 2, 2022 09:40
haffla pushed a commit to tourlane/cal.com that referenced this pull request Nov 22, 2022
* Buffer limits + remove redundant tests

* Fixing buffer

* Compound

* Afterbuffer fix for no event afterbuffer set

* Bug fixes

* Buffer includes eventType before
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge ♻️ autoupdate tells kodiak to keep this branch up-to-date

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants