Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Reduce payload even further. #13599

Merged
merged 4 commits into from
Feb 9, 2024
Merged

fix: Reduce payload even further. #13599

merged 4 commits into from
Feb 9, 2024

Conversation

hariombalhara
Copy link
Member

@hariombalhara hariombalhara commented Feb 8, 2024

Reverts #13588 and then improves upon the following to further decrease the payload size

  • Removes event-types from being available inside eventTypes[number].team
  • Deduplicate all users in the payload. event-type just has the reference to userId.

NOTE: Because the first commit is just a revert commit of #13588. Use this link to review the changes https://github.com/calcom/cal.com/pull/13599/files/309e073303c60e3cbaff7a24401883131b62d538..8d9df5ff92e007b11ffa7dde75185dc9dd6e77d9#diff-5294731b960e76c72f504ce7e1381d51e5c054131976fe7f43bb38f485d76aa6 (it excludes that revert commit)

Profile Based Querying - Before
image

Profile Based Querying - After - THIS BRANCH -> Though the time taken to serve it is significantly more than non-profile based querying, the payload is smaller. I am hoping this won't be a big issue in production. We can work on improving that later. I expect mostly increase is due to every user needing a join with profile now.
image

Non Profile Based Querying
image

Copy link

vercel bot commented Feb 8, 2024

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

Name Status Preview Comments Updated (UTC)
api 🔄 Building (Inspect) Visit Preview Feb 9, 2024 11:53am
6 Ignored Deployments
Name Status Preview Comments Updated (UTC)
ai ⬜️ Ignored (Inspect) Visit Preview Feb 9, 2024 11:53am
cal ⬜️ Ignored (Inspect) Visit Preview Feb 9, 2024 11:53am
cal-demo ⬜️ Ignored (Inspect) Feb 9, 2024 11:53am
calcom-web-canary ⬜️ Ignored (Inspect) Visit Preview Feb 9, 2024 11:53am
qa ⬜️ Ignored (Inspect) Visit Preview Feb 9, 2024 11:53am
ui ⬜️ Ignored (Inspect) Visit Preview Feb 9, 2024 11:53am

Copy link
Contributor

github-actions bot commented Feb 8, 2024

Thank you for following the naming conventions! 🙏 Feel free to join our discord and post your PR link.

@keithwillcode keithwillcode added consumer core area: core, team members only labels Feb 8, 2024
@hariombalhara hariombalhara changed the title Revert "Revert event-type profile based querying (#13588)" fix: Reduce payload even further. Feb 8, 2024
Copy link
Contributor

github-actions bot commented Feb 8, 2024

📦 Next.js Bundle Analysis for @calcom/web

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

Copy link

deploysentinel bot commented Feb 8, 2024

Current Playwright Test Results Summary

✅ 447 Passing - ⚠️ 20 Flaky

Run may still be in progress, this comment will be updated as current testing workflow or job completes...

(Last updated on 02/09/2024 12:15:01pm UTC)

Run Details

Running Workflow PR Update on Github Actions

Commit: 8d9df5f

Started: 02/09/2024 12:03:08pm UTC

⚠️ Flakes

📄   apps/web/playwright/impersonation.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Users can impersonate App Admin can impersonate users with impersonation enabled
Retry 1Initial Attempt
0.29% (1) 1 / 339 run
failed over last 7 days
9.73% (33) 33 / 339 runs
flaked over last 7 days

📄   apps/web/playwright/event-types.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Event Types tests -- future user can add multiple organizer address
Retry 1Initial Attempt
0.86% (3) 3 / 348 runs
failed over last 7 days
16.67% (58) 58 / 348 runs
flaked over last 7 days

📄   apps/web/playwright/booking/selectQuestion.e2e.ts • 2 Flakes

Top 1 Common Error Messages

null

2 Test Cases Affected

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Booking With Phone Question and Each Other Question Booking With Select Question and Address Question Select required and Address required
Retry 1Initial Attempt
0% (0) 0 / 308 runs
failed over last 7 days
4.55% (14) 14 / 308 runs
flaked over last 7 days
Booking With Phone Question and Each Other Question Booking With Select Question and Radio group Question Select required and Radio group required
Retry 1Initial Attempt
0% (0) 0 / 304 runs
failed over last 7 days
5.59% (17) 17 / 304 runs
flaked over last 7 days

📄   apps/web/playwright/booking/checkboxGroupQuestion.e2e.ts • 2 Flakes

Top 1 Common Error Messages

null

2 Test Cases Affected

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Booking With Checkbox Group Question and Each Other Question Booking With Checkbox Group Question and Address Question Booking With Checkbox Group Question and Radio group Question Checkbox Group and Radio group not required
Retry 1Initial Attempt
0% (0) 0 / 319 runs
failed over last 7 days
4.70% (15) 15 / 319 runs
flaked over last 7 days
Booking With Checkbox Group Question and Each Other Question Booking With Checkbox Group Question and Address Question Booking With Checkbox Group Question and select Question Checkbox Group required and select required
Retry 1Initial Attempt
0% (0) 0 / 319 runs
failed over last 7 days
5.64% (18) 18 / 319 runs
flaked over last 7 days

📄   apps/web/playwright/booking/responsiveBooking.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Booking page with no questions Booking page with 1920x1080 resolution
Retry 1Initial Attempt
0.32% (1) 1 / 309 run
failed over last 7 days
6.15% (19) 19 / 309 runs
flaked over last 7 days

📄   apps/web/playwright/webhook.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Webhook tests FORM_SUBMITTED on submitting user form, triggers user webhook
Retry 1Initial Attempt
0.93% (3) 3 / 323 runs
failed over last 7 days
5.26% (17) 17 / 323 runs
flaked over last 7 days

📄   apps/web/playwright/booking/addressQuestione2e/addressQuestion.e2e.ts • 2 Flakes

Top 1 Common Error Messages

null

2 Test Cases Affected

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Booking With Address Question and Each Other Question Booking With Address Question and Checkbox Question Address required and checkbox required
Retry 2Retry 1Initial Attempt
1.77% (6) 6 / 339 runs
failed over last 7 days
5.01% (17) 17 / 339 runs
flaked over last 7 days
Booking With Address Question and Each Other Question Booking With Address Question and Short text question Address required and Short text required
Retry 1Initial Attempt
0.61% (2) 2 / 328 runs
failed over last 7 days
4.57% (15) 15 / 328 runs
flaked over last 7 days

📄   apps/web/playwright/profile.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Update Profile Cannot update a users email when existing user has same email (verification enabled)
Retry 1Initial Attempt
0% (0) 0 / 75 runs
failed over last 7 days
54.67% (41) 41 / 75 runs
flaked over last 7 days

📄   packages/embeds/embed-core/playwright/tests/action-based.e2e.ts • 8 Flakes

Top 1 Common Error Messages

null

8 Test Cases Affected

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Popup Tests should open embed iframe on click - Configured with light theme
Retry 1Initial Attempt
-0.30% (-1) -1 / 332 runs
failed over last 7 days
52.71% (175) 175 / 332 runs
flaked over last 7 days
Popup Tests should be able to reschedule
Retry 1Initial Attempt
-111.46% (-175) -175 / 157 runs
failed over last 7 days
111.46% (175) 175 / 157 runs
flaked over last 7 days
Popup Tests should open Routing Forms embed on click
Retry 1Initial Attempt
-106.37% (-167) -167 / 157 runs
failed over last 7 days
107.01% (168) 168 / 157 runs
flaked over last 7 days
Popup Tests Floating Button Popup Pro User - Configured in App with default setting of system theme should open embed iframe according to system theme when no theme is configured through Embed API
Retry 1Initial Attempt
-107.69% (-168) -168 / 156 runs
failed over last 7 days
107.69% (168) 168 / 156 runs
flaked over last 7 days
Popup Tests Floating Button Popup Pro User - Configured in App with default setting of system theme should open embed iframe according to system theme when configured with 'auto' theme using Embed API
Retry 1Initial Attempt
-107.69% (-168) -168 / 156 runs
failed over last 7 days
107.69% (168) 168 / 156 runs
flaked over last 7 days
Popup Tests Floating Button Popup Pro User - Configured in App with default setting of system theme should open embed iframe(Booker Profile Page) with dark theme when configured with dark theme using Embed API
Retry 1Initial Attempt
-107.05% (-167) -167 / 156 runs
failed over last 7 days
107.05% (167) 167 / 156 runs
flaked over last 7 days
Popup Tests Floating Button Popup Pro User - Configured in App with default setting of system theme should open embed iframe(Event Booking Page) with dark theme when configured with dark theme using Embed API
Retry 1Initial Attempt
-107.05% (-167) -167 / 156 runs
failed over last 7 days
107.05% (167) 167 / 156 runs
flaked over last 7 days
Popup Tests prendered embed should be loaded and apply the config given to it
Retry 1Initial Attempt
-107.05% (-167) -167 / 156 runs
failed over last 7 days
107.05% (167) 167 / 156 runs
flaked over last 7 days

📄   packages/app-store/routing-forms/playwright/tests/basic.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Routing Forms Seeded Routing Form Router URL should work
Retry 1Initial Attempt
0.89% (3) 3 / 338 runs
failed over last 7 days
14.79% (50) 50 / 338 runs
flaked over last 7 days

View Detailed Build Results


@@ -1,16 +1,20 @@
import { Prisma } from "@prisma/client";
// eslint-disable-next-line no-restricted-imports
Copy link
Member Author

Choose a reason for hiding this comment

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

This file is the same as it was earlier before we reverted profile querying except for doing the normalization before sending the payload.

Comment on lines +293 to 325
return normalizePayload(denormalizedPayload);

/**
* Reduces the size of payload
*/
function normalizePayload(payload: typeof denormalizedPayload) {
const allUsersAcrossAllEventTypes = new Map<
number,
EventTypeGroup["eventTypes"][number]["users"][number]
>();
const eventTypeGroups = payload.eventTypeGroups.map((group) => {
return {
...group,
eventTypes: group.eventTypes.map((eventType) => {
const { users, ...rest } = eventType;
return {
...rest,
// Send userIds per event and keep the actual users object outside
userIds: users.map((user) => {
allUsersAcrossAllEventTypes.set(user.id, user);
return user.id;
}),
};
}),
};
});

return {
...payload,
allUsersAcrossAllEventTypes,
eventTypeGroups,
};
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the normalization change

(filters?.teamIds?.length === 1 || filters?.userIds?.length === 1) &&
rawData.eventTypeGroups.length === 1;

const data = denormalizePayload(rawData);
Copy link
Member Author

Choose a reason for hiding this comment

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

Because the sent payload is in a different format now, we need to denormalize it before others can keep consuming it without any change.

return (
<>
{data.eventTypeGroups.length > 1 || isFilteredByOnlyOneItem ? (
<>
{isMobile ? (
<MobileTeamsTab eventTypeGroups={data.eventTypeGroups} />
) : (
data.eventTypeGroups.map((group: EventTypeGroup, index: number) => (
data.eventTypeGroups.map((group, index: number) => (
Copy link
Member Author

Choose a reason for hiding this comment

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

Wasn't needed.

@@ -238,7 +260,7 @@ export const EventTypeList = ({
await utils.viewer.eventTypes.getByViewer.cancel();
const previousValue = utils.viewer.eventTypes.getByViewer.getData();
if (previousValue) {
const newList = [...types];
const newList = [...types.map(normalizeEventType)];
Copy link
Member Author

Choose a reason for hiding this comment

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

Optimistic updates need to do in memory conversion to make the format consistent with react query response for getByViewer

@hariombalhara hariombalhara marked this pull request as ready for review February 9, 2024 11:25
@@ -175,6 +166,7 @@ export class EventTypeRepository {
return await prisma.eventType.findMany({
where: {
profileId,
...where,
Copy link
Member Author

Choose a reason for hiding this comment

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

Missing where clause.

@PeerRich PeerRich added the High priority Created by Linear-GitHub Sync label Feb 9, 2024
@CarinaWolli CarinaWolli merged commit 7fef9db into main Feb 9, 2024
43 checks passed
@CarinaWolli CarinaWolli deleted the seed-huge-event-types branch February 9, 2024 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
consumer core area: core, team members only High priority Created by Linear-GitHub Sync Urgent Created by Linear-GitHub Sync
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants