Skip to content

Commit e7d3875

Browse files
authored
refactor: use DI-ed cached FeaturesRepository in flags router (calcom#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
1 parent 0e8dde8 commit e7d3875

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

packages/features/flags/server/router.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
import { z } from "zod";
2-
1+
import { getFeaturesRepository } from "@calcom/features/di/containers/FeaturesRepository";
32
import type { AppFlags } from "@calcom/features/flags/config";
4-
import { FeaturesRepository } from "@calcom/features/flags/features.repository";
5-
import { prisma } from "@calcom/prisma";
63
import publicProcedure from "@calcom/trpc/server/procedures/publicProcedure";
74
import { router } from "@calcom/trpc/server/trpc";
8-
5+
import { z } from "zod";
96
import { map } from "./procedures/map";
107

118
export const featureFlagRouter = router({
129
list: publicProcedure.query(async () => {
13-
const featuresRepository = new FeaturesRepository(prisma);
10+
const featuresRepository = getFeaturesRepository();
1411
return featuresRepository.getAllFeatures();
1512
}),
1613
checkTeamFeature: publicProcedure
@@ -21,7 +18,7 @@ export const featureFlagRouter = router({
2118
})
2219
)
2320
.query(async ({ input }) => {
24-
const featuresRepository = new FeaturesRepository(prisma);
21+
const featuresRepository = getFeaturesRepository();
2522
return featuresRepository.checkIfTeamHasFeature(input.teamId, input.feature as keyof AppFlags);
2623
}),
2724
map,

0 commit comments

Comments
 (0)