From e7d38755dd45a62fb5760d06d210549c3e955fef Mon Sep 17 00:00:00 2001 From: Eunjae Lee Date: Thu, 29 Jan 2026 16:47:46 +0100 Subject: [PATCH] refactor: use DI-ed cached FeaturesRepository in flags router (#27394) ## What does this PR do? Replaces direct instantiation of `FeaturesRepository` with the dependency-injected version using `getFeaturesRepository()` from the DI container in the feature flags router. **Key improvement:** The DI-ed version uses Redis caching, replacing the previous in-memory 5-minute cache implementation which was not ideal. This follows the established DI pattern in the codebase for loose coupling, better testability, and more robust caching across instances. ## Type of change - [x] Refactor (non-breaking change that improves code quality) ## Mandatory Tasks (DO NOT REMOVE) - [x] I have self-reviewed the code (A decent size PR without self-review might be rejected). - [x] I have updated the developer docs in /docs if this PR makes changes that would require a [documentation change](https://cal.com/docs). N/A - no documentation changes needed. - [x] I confirm automated tests are in place that prove my fix is effective or that my feature works. ## How should this be tested? 1. Verify feature flags functionality works as expected: - Feature flag list endpoint should return all features - Team feature check should work correctly 2. No environment variables needed beyond standard setup ## Checklist - [x] My code follows the style guidelines of this project - [x] I have checked if my changes generate no new warnings ## Human Review Checklist - [ ] Verify `getFeaturesRepository()` returns a properly configured instance from the DI container - [ ] Confirm the DI container properly injects the Prisma client - [ ] Verify Redis caching is working as expected for feature flag data --- **Link to Devin run:** https://app.devin.ai/sessions/2ff6e4551c8649e4b6178b31a2195327 **Requested by:** @eunjae-lee --- packages/features/flags/server/router.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/features/flags/server/router.ts b/packages/features/flags/server/router.ts index 5327509c08..0922806285 100644 --- a/packages/features/flags/server/router.ts +++ b/packages/features/flags/server/router.ts @@ -1,16 +1,13 @@ -import { z } from "zod"; - +import { getFeaturesRepository } from "@calcom/features/di/containers/FeaturesRepository"; import type { AppFlags } from "@calcom/features/flags/config"; -import { FeaturesRepository } from "@calcom/features/flags/features.repository"; -import { prisma } from "@calcom/prisma"; import publicProcedure from "@calcom/trpc/server/procedures/publicProcedure"; import { router } from "@calcom/trpc/server/trpc"; - +import { z } from "zod"; import { map } from "./procedures/map"; export const featureFlagRouter = router({ list: publicProcedure.query(async () => { - const featuresRepository = new FeaturesRepository(prisma); + const featuresRepository = getFeaturesRepository(); return featuresRepository.getAllFeatures(); }), checkTeamFeature: publicProcedure @@ -21,7 +18,7 @@ export const featureFlagRouter = router({ }) ) .query(async ({ input }) => { - const featuresRepository = new FeaturesRepository(prisma); + const featuresRepository = getFeaturesRepository(); return featuresRepository.checkIfTeamHasFeature(input.teamId, input.feature as keyof AppFlags); }), map,