Skip to content

fix: Feature flag user cache#10359

Merged
zomars merged 5 commits into
mainfrom
fix/feature-flag-cache
Jul 25, 2023
Merged

fix: Feature flag user cache#10359
zomars merged 5 commits into
mainfrom
fix/feature-flag-cache

Conversation

@sean-brydon
Copy link
Copy Markdown
Member

Adds feature flags to cache after its ran once. We very rarley change this and it isnt needed to be fetched each time

CleanShot 2023-07-25 at 09 52 17

@vercel
Copy link
Copy Markdown

vercel Bot commented Jul 25, 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 Jul 25, 2023 9:58pm
cal-demo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 25, 2023 9:58pm
dev ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 25, 2023 9:58pm
ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 25, 2023 9:58pm
2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
cal ⬜️ Ignored (Inspect) Jul 25, 2023 9:58pm
qa ⬜️ Ignored (Inspect) Jul 25, 2023 9:58pm

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jul 25, 2023

Thank you for following the naming conventions! 🙏

@zomars zomars added the core area: core, team members only label Jul 25, 2023
} = props;
const utils = trpc.useContext();
const mutation = trpc.viewer.features.toggle.useMutation({
const mutation = trpc.viewer.admin.toggleFeatureFlag.useMutation({
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Moved to admin so we can set the cache control on the createNextAPIHandler to true as a result of isPublic=true

Comment on lines -20 to -29
toggle: authedAdminProcedure
.input(z.object({ slug: z.string(), enabled: z.boolean() }))
.mutation(({ ctx, input }) => {
const { prisma, user } = ctx;
const { slug, enabled } = input;
return prisma.feature.update({
where: { slug },
data: { enabled, updatedBy: user.id },
});
}),
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Moved to admin as its a better fit there IMHO

Comment thread packages/trpc/server/createNextApiHandler.ts Outdated
@alwaysmeticulous
Copy link
Copy Markdown

alwaysmeticulous Bot commented Jul 25, 2023

🤖 Meticulous spotted visual differences in 26 of 271 screens tested: view and approve differences detected.

Last updated for commit 5951658. This comment will update as new commits are pushed.

keithwillcode
keithwillcode previously approved these changes Jul 25, 2023
@sean-brydon sean-brydon added the performance area: performance, page load, slow, slow endpoints, loading screen, unresponsive label Jul 25, 2023
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jul 25, 2023

📦 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! 🙌

@deploysentinel
Copy link
Copy Markdown

deploysentinel Bot commented Jul 25, 2023

Current Playwright Test Results Summary

✅ 105 Passing - ⚠️ 1 Flaky

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

(Last updated on 07/25/2023 09:59:40pm UTC)

Run Details

Running Workflow PR Update on Github Actions

Commit: 5951658

Started: 07/25/2023 09:58:02pm UTC

⚠️ Flakes

📄   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
1.55% (3) 3 / 193 runs
failed over last 7 days
97.93% (189) 189 / 193 runs
flaked over last 7 days

View Detailed Build Results


// Revalidation time here should be 1 second, per https://github.com/calcom/cal.com/pull/6823#issuecomment-1423215321
"slots.getSchedule": `no-cache`, // FIXME
cityTimezones: `max-age=${ONE_DAY_IN_SECONDS}, stale-while-revalidate`,
map: `max-age=${ONE_DAY_IN_SECONDS}, stale-while-revalidate`, // "map" - Feature Flag Map
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This approach of mapping cacheRules can give unexpected results as it isn't checking for full path. So, there can be features.map and example.map. This cache header would be applied to both I guess?

This isn't related to the PR, so it's non blocking but should be fixed I guess.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh i guess youre right -> We could rename this route to something more specific so this doesnt happen?

Copy link
Copy Markdown
Member

@hariombalhara hariombalhara Jul 25, 2023

Choose a reason for hiding this comment

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

Also, this is going to consider the response fresh for a day. We might not be able to disable/enable a feature for our users within a good amount of time which is an important thing IMHO.

Also, I suspect a weird issue with this
We might end up in a scenario like this

  • Say, a feature F1 was disabled and thus it's cached across all our users' browsers
  • We disable Feature F1, now, backend code knows immediately that F1 is disabled but frontend won't realize it and it might keep showing F1 in UI and taking action on that feature would be rejected by server(as it knows feature is disabled).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the approach to solve the multiple requests for flag might be to configure react-query in such a way that the request goes only once from one pageview. Only, on hard refresh we send a new request.

Above scenario can still happen in here, but user can always refresh the page

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.

Using stale while revalidate will prevent stale data for more than a few seconds

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.

Pushing a fix for the namespace issue

image

Copy link
Copy Markdown
Member

@hariombalhara hariombalhara left a comment

Choose a reason for hiding this comment

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

Left some comments

import { createNextApiHandler } from "@calcom/trpc/server/createNextApiHandler";

export default createNextApiHandler(featureFlagRouter);
export default createNextApiHandler(featureFlagRouter, true, "features");
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.

We can now optionally namespace api handlers to distinguish them @sean-brydon @hariombalhara

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.

Tested and addressed @hariombalhara concerns 🙏🏽

@keithwillcode keithwillcode dismissed hariombalhara’s stale review July 25, 2023 17:44

Changes implemented

@zomars zomars merged commit ad3bdbb into main Jul 25, 2023
@zomars zomars deleted the fix/feature-flag-cache branch July 25, 2023 22:00
joeauyeung pushed a commit that referenced this pull request Jul 26, 2023
Co-authored-by: zomars <zomars@me.com>
sean-brydon added a commit that referenced this pull request Jul 31, 2023
Co-authored-by: zomars <zomars@me.com>
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 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.

5 participants