fix: Feature flag user cache#10359
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
Thank you for following the naming conventions! 🙏 |
| } = props; | ||
| const utils = trpc.useContext(); | ||
| const mutation = trpc.viewer.features.toggle.useMutation({ | ||
| const mutation = trpc.viewer.admin.toggleFeatureFlag.useMutation({ |
There was a problem hiding this comment.
Moved to admin so we can set the cache control on the createNextAPIHandler to true as a result of isPublic=true
| 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 }, | ||
| }); | ||
| }), |
There was a problem hiding this comment.
Moved to admin as its a better fit there IMHO
|
🤖 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. |
📦 Next.js Bundle Analysis for @calcom/webThis analysis was generated by the Next.js Bundle Analysis action. 🤖 This PR introduced no changes to the JavaScript bundle! 🙌 |
Current Playwright Test Results Summary✅ 105 Passing - 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 DetailsRunning Workflow PR Update on Github Actions Commit: 5951658 Started: 07/25/2023 09:58:02pm UTC
|
| Test Case | Last 7 days Failures | Last 7 days Flakes |
|---|---|---|
|
Popup Tests should be able to reschedule
Retry 1 • Initial Attempt |
1.55% (3)3 / 193 runsfailed over last 7 days |
97.93% (189)189 / 193 runsflaked over last 7 days |
| // 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Oh i guess youre right -> We could rename this route to something more specific so this doesnt happen?
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Using stale while revalidate will prevent stale data for more than a few seconds
| import { createNextApiHandler } from "@calcom/trpc/server/createNextApiHandler"; | ||
|
|
||
| export default createNextApiHandler(featureFlagRouter); | ||
| export default createNextApiHandler(featureFlagRouter, true, "features"); |
There was a problem hiding this comment.
We can now optionally namespace api handlers to distinguish them @sean-brydon @hariombalhara
zomars
left a comment
There was a problem hiding this comment.
Tested and addressed @hariombalhara concerns 🙏🏽
Co-authored-by: zomars <zomars@me.com>
Co-authored-by: zomars <zomars@me.com>

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