feat: attribute weights and virtual queues (#17567)

* only fetch bookings of this month for weighted rr

* test set up

* only get bookings of current month

* reverts test setup

* first changes for weight adjustments

* reset booking count + adjust calibration

* depreciate weightAdjustment

* get only bookings created this month

* fix typo

* make sure createdAt for hosts is correct

* use earliest possibel date as fallback

* add missing createdAt date to tests

* fix typo

* clean up changes in tests

* fix typo

* change end date to current date

* fix: Fall back to empty host array when no hosts are found

* fix: Restructure code a little

* fixed test, incorrectly used now outdated var

* perf: remove Dayjs from getLuckyUser

* Refactor getHostsWithCalibration for optimised performance, intentionally break test as findMany is always an array

* Better mock for host.findMany

* Remove team-event-types.test.ts, move to appropriate package

* TypeScript cannot auto-infer that an array is non-empty when assigning to a var

* fix: Type Fixes and DistributionMethod enum add

* Optimise tests

* Added test to show that bookings made before a newHost was added affect the lucky user result

* Throw error when the usersWithHighestPriority is empty, which should never happen

* WIP

* remove comment

* update migrations

* get attributes weights and virtual queue data

* use attribute weights and use bookings of virtual queue only

* clean up migrations

* code clean up from feedback

* wrapper function for getLuckyUser

* code clean up

* fetch routingFormResponse in handleNewBooking

* fix type errors

* fix type errors in tests

* fix getAttributesQueryValue import for tests

* fix totalWeight

* add test for attributes weights and virtual queues

* clean up code

* add test for prepareQueuesAndAttributesData

* remove console.log

* use lazy import

* use findUnique

* add fallback weight

---------

Co-authored-by: CarinaWolli <[email protected]>
Co-authored-by: Alex van Andel <[email protected]>
This commit is contained in:
authored and GitHub committed 2024-11-15 17:36:46 +00:00
1 parent 322ca2a12c
commit 5012a16794
12 files changed
+892 -87

No files matched your search

@@ -467,13 +467,38 @@ async function handler(
eventType.schedulingType === SchedulingType.ROUND_ROBIN &&
eventType.rescheduleWithSameRoundRobinHost;
const userIdsSet = new Set(users.map((user) => user.id));
let routingFormResponse;
if (routedTeamMemberIds) {
routingFormResponse = await prisma.app_RoutingForms_FormResponse.findUnique({
where: {
id: routingFormResponseId,
},
select: {
response: true,
form: {
select: {
routes: true,
fields: true,
},
},
chosenRouteId: true,
},
});
}
const newLuckyUser = isSameRoundRobinHost
? freeUsers.find((user) => user.id === originalRescheduledBookingUserId)
: await getLuckyUser({
// find a lucky user that is not already in the luckyUsers array
availableUsers: freeUsers,
allRRHosts: eventTypeWithUsers.hosts.filter((host) => !host.isFixed),
allRRHosts: eventTypeWithUsers.hosts.filter(
(host) => !host.isFixed && userIdsSet.has(host.user.id)
), // users part of virtual queue
eventType,
routingFormResponse,
});
if (!newLuckyUser) {
break; // prevent infinite loop
@@ -127,11 +127,8 @@ export const roundRobinReassignment = async ({
const reassignedRRHost = await getLuckyUser({
availableUsers,
eventType: {
id: eventType.id,
isRRWeightsEnabled: eventType.isRRWeightsEnabled,
},
allRRHosts: eventType.hosts.filter((host) => !host.isFixed),
eventType,
allRRHosts: eventType.hosts.filter((host) => !host.isFixed), // todo: only use hosts from virtual queue
});
const hasOrganizerChanged = !previousRRHost || booking.userId === previousRRHost?.id;
@@ -12,9 +12,8 @@ import { MembershipRole, SchedulingType } from "@calcom/prisma/enums";
import { trpc } from "@calcom/trpc/react";
import { Button, Dialog, DialogClose, DialogContent, DialogFooter, showToast } from "@calcom/ui";
import CreateEventTypeForm from "./CreateEventTypeForm";
import usePostHog from "../../ee/event-tracking/lib/posthog/userPostHog";
import CreateEventTypeForm from "./CreateEventTypeForm";
// this describes the uniform data needed to create a new event type on Profile or Team
export interface EventTypeParent {
+1 -1
View File
@@ -23,7 +23,7 @@ const ClearFilters = () => {
color="secondary"
target="_blank"
rel="noreferrer"
className="h-[38px] min-w-24 border-0"
className="min-w-24 h-[38px] border-0"
onClick={() => {
clearFilters();
}}>