refactor: replace FeaturesRepository with DI-based feature repositories#27200
refactor: replace FeaturesRepository with DI-based feature repositories#27200
Conversation
|
@cubic-dev-ai review this PR |
@eunjae-lee I have started the AI code review. It will take a few minutes to complete. |
fcd9b24 to
0f825f1
Compare
0f825f1 to
3943f48
Compare
3943f48 to
c0ff989
Compare
E2E results are ready! |
Migrate from the legacy FeaturesRepository pattern to separate DI-based repositories: - Add checkIfFeatureIsEnabledGlobally to IFeatureRepository - Add getTeamsWithFeatureEnabled to ITeamFeatureRepository - Update CalendarSubscriptionService to use featureRepository, teamFeatureRepository, and userFeatureRepository - Update SelectedCalendarRepository.findNextSubscriptionBatch to filter by teamIds instead of featureIds - Update OnboardingPathService to use DI via getFeatureRepository() - Remove prisma parameter from OnboardingPathService callsites Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
a8b519f to
329f75d
Compare
Update CalendarSubscriptionService and SelectedCalendarRepository tests to use the new separate repository interfaces: - featureRepository for global feature checks - teamFeatureRepository for team-level feature checks - userFeatureRepository for user-level feature checks Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Update cron and webhook routes to use the new separate repository interfaces instead of the combined FeaturesRepository. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The OnboardingPathService method no longer requires a prisma argument as it now uses DI containers internally. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Update service instantiation tests to expect featureRepository, teamFeatureRepository, and userFeatureRepository instead of the old featuresRepository. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
2 issues found across 21 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="packages/features/flags/repositories/PrismaFeatureRepository.ts">
<violation number="1" location="packages/features/flags/repositories/PrismaFeatureRepository.ts:73">
P2: This global feature check only needs the enabled flag, but it fetches the full FeatureDto via findBySlug. Querying all columns adds unnecessary DB I/O and data exposure. Use a targeted select for enabled.
(Based on your team's feedback about selecting only required Prisma fields.) [FEEDBACK_USED]</violation>
</file>
<file name="packages/features/calendar-subscription/lib/CalendarSubscriptionService.ts">
<violation number="1" location="packages/features/calendar-subscription/lib/CalendarSubscriptionService.ts:396">
P2: checkForNewSubscriptions no longer gates on the global cache feature flag. Because PrismaTeamFeatureRepository.getTeamsWithFeatureEnabled does not check global enablement, the subscription cron will run for team-enabled rows even when the global flag is disabled. Add a global flag guard before fetching team IDs to preserve previous behavior.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Devin AI is addressing Cubic AI's review feedbackA Devin session has been created to address the issues identified by Cubic AI. |
| import type { PrismaClient } from "@calcom/prisma"; | ||
| import { getFeatureRepository } from "@calcom/features/di/containers/FeatureRepository"; | ||
|
|
||
| export class OnboardingPathService { |
There was a problem hiding this comment.
Why are we calling getFeatureRepository within functions of OnboardingPathService instead of dependency injecting getFeatureRepository via constructor of OnboardingPathService when it is instantiated? How big of a lift it is to make that happen? Technically not scope of this PR but still wanted to note it.
There was a problem hiding this comment.
it's named "Service" but I feel like it's more of a utility. So I'm not too sure if it makes sense to make OnboardingPathService DI-ed.
…iptions - Use targeted select for only `enabled` field in checkIfFeatureIsEnabledGlobally - Add global feature flag guard in checkForNewSubscriptions to avoid unnecessary DB queries and API calls when the cache feature is globally disabled Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Paragon: tests updated2 updated tests generated for this PR. Updated Tests
DetailsUpdated Tests
|


Summary
This PR refactors the codebase to replace the legacy combined
FeaturesRepositorywith separate DI-based repositories:IFeatureRepository/PrismaFeatureRepository- Global feature flag checks (checkIfFeatureIsEnabledGlobally)ITeamFeatureRepository/PrismaTeamFeatureRepository- Team-level feature checks (checkIfTeamHasFeature,getTeamsWithFeatureEnabled)IUserFeatureRepository/PrismaUserFeatureRepository- User-level feature checks (checkIfUserHasFeature)Key Changes
Added
checkIfFeatureIsEnabledGloballytoIFeatureRepository- Moved global feature check method to the correct interfaceUpdated
CalendarSubscriptionService- Now uses three separate feature repositories instead of the combinedFeaturesRepositoryUpdated
SelectedCalendarRepository.findNextSubscriptionBatch- Changed fromfeatureIds: string[]toteamIds: number[]parameter for more efficient team-based filteringUpdated
OnboardingPathService- Now uses DI container to get the feature repositoryUpdated all callsites - Removed direct prisma parameter passing where DI containers are now used
Test plan
CalendarSubscriptionServiceSelectedCalendarRepository🤖 Generated with Claude Code