Skip to content

Commit

Permalink
perf: improve routing insights view (2) (#18566)
Browse files Browse the repository at this point in the history
  • Loading branch information
eunjae-lee authored Jan 14, 2025
1 parent a8c29b5 commit 21694c0
Showing 1 changed file with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
CREATE OR REPLACE VIEW "RoutingFormResponse" AS
SELECT
r.id,
r.response,
(
SELECT jsonb_object_agg(
key,
CASE
WHEN jsonb_typeof(value->'value') = 'string'
THEN jsonb_build_object(
'label', value->'label',
'value', lower((value->>'value')::text)
)
ELSE value
END
)
FROM jsonb_each(r.response::jsonb)
) as "responseLowercase",
f.id as "formId",
f.name as "formName",
f."teamId" as "formTeamId",
f."userId" as "formUserId",
b.uid as "bookingUid",
b.status as "bookingStatus",
CASE b.status
WHEN 'accepted' THEN 1
WHEN 'pending' THEN 2
WHEN 'awaiting_host' THEN 3
WHEN 'cancelled' THEN 4
WHEN 'rejected' THEN 5
END as "bookingStatusOrder",
b."createdAt" as "bookingCreatedAt",
b."startTime" as "bookingStartTime",
b."endTime" as "bookingEndTime",
(SELECT
json_agg(
json_build_object(
'name', a.name, 'timeZone', a."timeZone", 'email', a.email
)
)
FROM "Attendee" a
WHERE "a"."bookingId" = b.id
) as "bookingAttendees",
u.id as "bookingUserId",
u.name as "bookingUserName",
u.email as "bookingUserEmail",
u."avatarUrl" as "bookingUserAvatarUrl",
COALESCE(
(
SELECT
ar."reasonString"
FROM "AssignmentReason" ar
WHERE ar."bookingId" = b.id
LIMIT 1
),
''
) as "bookingAssignmentReason",
COALESCE(
(
SELECT
LOWER(ar."reasonString")
FROM "AssignmentReason" ar
WHERE ar."bookingId" = b.id
LIMIT 1
),
''
) as "bookingAssignmentReasonLowercase",
r."createdAt" as "createdAt"
FROM "App_RoutingForms_FormResponse" r
LEFT JOIN "App_RoutingForms_Form" f ON r."formId" = f.id
LEFT JOIN "Booking" b ON r."routedToBookingUid" = b.uid
LEFT JOIN "users" u ON b."userId" = u.id

0 comments on commit 21694c0

Please sign in to comment.