From 0eae50ca2179cd13c09baccf5ea1828f79e13e9d Mon Sep 17 00:00:00 2001 From: Karl Ludwig Weise Date: Wed, 22 Jul 2026 12:30:28 +0200 Subject: [PATCH] Speed up calendar response time by removing agent data from calendar response --- .../__tests__/schedule-service.test.ts | 4 -- src/lib/server/services/schedule-service.ts | 10 +-- src/lib/types/calendar.ts | 5 +- .../add-appointment/SelectAgent.svelte | 62 ++++++++++--------- 4 files changed, 42 insertions(+), 39 deletions(-) diff --git a/src/lib/server/services/__tests__/schedule-service.test.ts b/src/lib/server/services/__tests__/schedule-service.test.ts index 1bf3868..9719caa 100644 --- a/src/lib/server/services/__tests__/schedule-service.test.ts +++ b/src/lib/server/services/__tests__/schedule-service.test.ts @@ -186,9 +186,6 @@ describe("ScheduleService", () => { channelId: "channel1", agent: { id: "agent1", - name: "Test Agent", - description: "Test Description", - logo: null, }, }, ]; @@ -241,7 +238,6 @@ describe("ScheduleService", () => { expect(actualSlot.duration).toBe(60); // 60-minute slots expect(actualSlot.availableAgents).toHaveLength(1); expect(actualSlot.availableAgents[0].id).toBe("agent1"); - expect(actualSlot.availableAgents[0].name).toBe("Test Agent"); }); }); diff --git a/src/lib/server/services/schedule-service.ts b/src/lib/server/services/schedule-service.ts index c22e099..fbce392 100644 --- a/src/lib/server/services/schedule-service.ts +++ b/src/lib/server/services/schedule-service.ts @@ -29,11 +29,13 @@ const scheduleRequestSchema = z.object({ export type ScheduleRequest = z.infer; +export type CalendarAgent = Pick; + export interface TimeSlot { from: string; // UTC ISO timestamp to: string; // UTC ISO timestamp duration: number; // minutes - availableAgents: SelectAgent[]; + availableAgents: CalendarAgent[]; } export interface AppointmentWithKeyShare extends SelectAppointment { @@ -201,7 +203,7 @@ export class ScheduleService { let channelAgents = await db .select({ channelId: tenantSchema.channelAgent.channelId, - agent: tenantSchema.agent, + agent: { id: tenantSchema.agent.id }, }) .from(tenantSchema.channelAgent) .innerJoin( @@ -266,7 +268,7 @@ export class ScheduleService { slotTemplates: { slotTemplate: SelectSlotTemplate; channelId: string }[]; appointments: SelectAppointment[]; absences: SelectAgentAbsence[]; - channelAgents: { channelId: string; agent: SelectAgent }[]; + channelAgents: { channelId: string; agent: CalendarAgent }[]; staffKeyShares: Record; timeZone: string; }): Promise { @@ -357,7 +359,7 @@ export class ScheduleService { date: Date; slotTemplates: SelectSlotTemplate[]; appointments: SelectAppointment[]; - agents: SelectAgent[]; + agents: CalendarAgent[]; absences: SelectAgentAbsence[]; timeZone: string; }): TimeSlot[] { diff --git a/src/lib/types/calendar.ts b/src/lib/types/calendar.ts index 98645fe..f7a21c0 100644 --- a/src/lib/types/calendar.ts +++ b/src/lib/types/calendar.ts @@ -1,5 +1,4 @@ -import type { SelectAgent } from "$lib/server/db/tenant-schema"; -import type { DaySchedule } from "$lib/server/services/schedule-service"; +import type { CalendarAgent, DaySchedule } from "$lib/server/services/schedule-service"; export type AppointmentStatus = "available" | "booked" | "reserved"; export type TAppointmentFilter = "all" | AppointmentStatus; @@ -33,5 +32,5 @@ export type TCalendarSlot = { color: string | null; column: number; channelId: string; - availableAgents?: SelectAgent[]; + availableAgents?: CalendarAgent[]; }; diff --git a/src/routes/(pages)/dashboard/calendar/(components)/add-appointment/SelectAgent.svelte b/src/routes/(pages)/dashboard/calendar/(components)/add-appointment/SelectAgent.svelte index 9dbc0af..cf11a16 100644 --- a/src/routes/(pages)/dashboard/calendar/(components)/add-appointment/SelectAgent.svelte +++ b/src/routes/(pages)/dashboard/calendar/(components)/add-appointment/SelectAgent.svelte @@ -2,9 +2,10 @@ import { m } from "$i18n/messages"; import { Button } from "$lib/components/ui/button"; import { Text } from "$lib/components/ui/typography"; - import type { SelectAgent } from "$lib/server/db/tenant-schema"; - import type { TAddAppointment } from "./types"; + import type { CalendarAgent } from "$lib/server/services/schedule-service"; + import { agents as agentsStore } from "$lib/stores/agents"; import UnknownItemIcon from "@lucide/svelte/icons/user-star"; + import type { TAddAppointment } from "./types"; let { newAppointment, @@ -12,9 +13,11 @@ proceed, }: { newAppointment: TAddAppointment; - availableAgents: SelectAgent[]; + availableAgents: CalendarAgent[]; proceed: (data: TAddAppointment) => void; } = $props(); + + let agents = $derived($agentsStore.agents);
@@ -23,31 +26,34 @@
    {#each availableAgents as agent (agent.id)} -
  • - -
  • + {@const agentItem = agents.find((it) => it.id === agent.id)} + {#if agentItem} +
  • + +
  • + {/if} {/each}