Skip to content

perf: Cache translations per language/per release#10843

Merged
zomars merged 8 commits into
mainfrom
perf/i18n-caching
Aug 19, 2023
Merged

perf: Cache translations per language/per release#10843
zomars merged 8 commits into
mainfrom
perf/i18n-caching

Conversation

@keithwillcode
Copy link
Copy Markdown
Contributor

@keithwillcode keithwillcode commented Aug 18, 2023

What does this PR do?

Fixes #10198

Type of change

  • Chore (refactoring code, technical debt, workflow improvements)

How should this be tested?

  • Changing language saves the setting and updates the interface to that new language.
  • Coming to the site as a logged out user uses the language preference from your machine/browser
  • The requested URL for i18n always includes the locale and the version number (if it doesn't include the locale and the version number, we risk caching data for too long and missing new translations upon upgrade)

Mandatory Tasks

  • Make sure you have self-reviewed the code. A decent size PR without self-review might be rejected.

@vercel
Copy link
Copy Markdown

vercel Bot commented Aug 18, 2023

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

Name Status Preview Comments Updated (UTC)
api ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 19, 2023 0:08am
cal-demo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 19, 2023 0:08am
dev ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 19, 2023 0:08am
ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 19, 2023 0:08am
2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
cal ⬜️ Ignored (Inspect) Visit Preview Aug 19, 2023 0:08am
qa ⬜️ Ignored (Inspect) Visit Preview Aug 19, 2023 0:08am

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Aug 18, 2023

Thank you for following the naming conventions! 🙏

@zomars zomars added the core area: core, team members only label Aug 18, 2023
import { useEffect } from "react";

import { trpc } from "@calcom/trpc/react";
import { CalComVersion } from "@calcom/ui/components/credits/Credits";
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ideally this goes into a different file than its current component. Then, it can be reused across both components that need it.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Aug 18, 2023

📦 Next.js Bundle Analysis for @calcom/web

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

Ten Pages Changed Size

The following pages changed size from the code in this PR compared to its base branch:

Page Size (compressed) First Load % of Budget (350 KB)
/booking/[uid] 183.64 KB 338.35 KB 96.67% (🟢 -0.16%)
/bookings/[status] 332.72 KB 487.43 KB 139.27% (🟢 -0.36%)
/event-types 517.73 KB 672.45 KB 192.13% (🟢 -0.28%)
/event-types/[type] 370.22 KB 524.94 KB 149.98% (🟢 -0.21%)
/getting-started/[[...step]] 395.46 KB 550.18 KB 157.19% (🟡 +1.57%)
/settings/admin/kycVerification/kycVerificationView 64.34 KB 219.06 KB 62.59% (🟡 +0.17%)
/settings/my-account/profile 375.68 KB 530.39 KB 151.54% (🟡 +1.11%)
/settings/organizations/teams/other/[id]/profile 438.19 KB 592.9 KB 169.40% (🟢 -0.19%)
/settings/teams/[id]/onboard-members 162.47 KB 317.19 KB 90.62% (🟡 +3.04%)
/settings/teams/[id]/profile 438.57 KB 593.28 KB 169.51% (🟢 -0.19%)
Details

Only the gzipped size is provided here based on an expert tip.

First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If next/link is used, subsequent page loads would only need to download that page's bundle (the number in the "Size" column), since the global bundle has already been downloaded.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

The "Budget %" column shows what percentage of your performance budget the First Load total takes up. For example, if your budget was 100kb, and a given page's first load size was 10kb, it would be 10% of your budget. You can also see how much this has increased or decreased compared to the base branch of your PR. If this percentage has increased by 20% or more, there will be a red status indicator applied, indicating that special attention should be given to this. If you see "+/- <0.01%" it means that there was a change in bundle size, but it is a trivial enough amount that it can be ignored.

@deploysentinel
Copy link
Copy Markdown

deploysentinel Bot commented Aug 18, 2023

Current Playwright Test Results Summary

✅ 116 Passing - ⚠️ 2 Flaky

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

(Last updated on 08/19/2023 12:09:13am UTC)

Run Details

Running Workflow PR Update on Github Actions

Commit: e79c545

Started: 08/19/2023 12:07:55am UTC

⚠️ Flakes

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

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Managed Event Types tests Can create managed event type
Retry 1Initial Attempt
0.77% (2) 2 / 259 runs
failed over last 7 days
12.74% (33) 33 / 259 runs
flaked over last 7 days

📄   packages/embeds/embed-core/playwright/tests/action-based.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Popup Tests should be able to reschedule
Retry 1Initial Attempt
2.33% (6) 6 / 257 runs
failed over last 7 days
97.67% (251) 251 / 257 runs
flaked over last 7 days

View Detailed Build Results


await utils.viewer.me.invalidate();
reset(getValues());
showToast(t("settings_updated_successfully"), "success");
update(res);
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.

This was causing the locale to not change when updating your profile

},
onSettled: async () => {
await utils.viewer.public.i18n.invalidate();
await utils.viewer.me.invalidate();
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.

No need to invalidate the i18n endpoint anymore. We just refetch the updated user

},
});
// eslint-disable-next-line turbo/no-undeclared-env-vars
const vercelCommitHash = process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA || "NA";
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.

The commit hash should be enough for now. WDYT @keithwillcode

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah that works too!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@zomars thinking about this more; if someone is self-hosting and not on Vercel, this would request the i18n endpoint with NA, which means the next time they upgrade, the new translations wouldn’t be pulled by the browser because the request URL would be the same.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I believe I'm having an issue related with this, when I deploy the changes to production the translations are never updated. Could it be the reason?

@zomars zomars marked this pull request as ready for review August 18, 2023 22:58
Copy link
Copy Markdown
Contributor

@zomars zomars left a comment

Choose a reason for hiding this comment

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

I think this is in a merge-able state. Nice work @keithwillcode 🙏🏽

Copy link
Copy Markdown
Contributor

@zomars zomars left a comment

Choose a reason for hiding this comment

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

Spoke too soon. Blocking to push some fixes.

await utils.viewer.me.invalidate();
},
async onSettled() {
await utils.viewer.public.i18n.invalidate();
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.

No need to invalidate now

Copy link
Copy Markdown
Contributor

@zomars zomars left a comment

Choose a reason for hiding this comment

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

All green now

Ship it

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.

Unused now

@zomars zomars merged commit 3f27323 into main Aug 19, 2023
@zomars zomars deleted the perf/i18n-caching branch August 19, 2023 00:46
@zomars zomars restored the perf/i18n-caching branch August 19, 2023 01:27
@zomars zomars mentioned this pull request Aug 19, 2023
4 tasks
@keithwillcode keithwillcode added High priority Created by Linear-GitHub Sync i18n area: i18n, translations performance area: performance, page load, slow, slow endpoints, loading screen, unresponsive labels Aug 21, 2023
Copy link
Copy Markdown
Contributor

@shivamklr shivamklr left a comment

Choose a reason for hiding this comment

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

Tested, lgtm

@keithwillcode keithwillcode deleted the perf/i18n-caching branch September 17, 2025 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core area: core, team members only High priority Created by Linear-GitHub Sync i18n area: i18n, translations performance area: performance, page load, slow, slow endpoints, loading screen, unresponsive

Projects

No open projects
Status: No status

Development

Successfully merging this pull request may close these issues.

[CAL-2192] RFC: Make the i18n serving endpoint "cache-able"

4 participants