perf: Calendar Cache Improvements (#25502)

* wip

* Filter only selectedCalendars where ff is enabled

* test: fix and add tests for calendar subscription cache feature

Co-Authored-By: Volnei Munhoz <[email protected]>

* test: fix SelectedCalendarRepository tests for new teamIds parameter

Co-Authored-By: Volnei Munhoz <[email protected]>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2025-12-02 08:11:52 -03:00
1 parent 3bf2a8fa6c
commit 2c8ff89fac
7 files changed
+158 -34

No files matched your search

@@ -4,4 +4,5 @@ export interface IFeaturesRepository {
checkIfFeatureIsEnabledGlobally(slug: keyof AppFlags): Promise<boolean>;
checkIfUserHasFeature(userId: number, slug: string): Promise<boolean>;
checkIfTeamHasFeature(teamId: number, slug: keyof AppFlags): Promise<boolean>;
getTeamsWithFeatureEnabled(slug: keyof AppFlags): Promise<number[]>;
}
@@ -351,4 +351,23 @@ export class FeaturesRepository implements IFeaturesRepository {
throw err;
}
}
async getTeamsWithFeatureEnabled(slug: keyof AppFlags): Promise<number[]> {
try {
// If globally disabled, treat as effectively disabled everywhere
const isGloballyEnabled = await this.checkIfFeatureIsEnabledGlobally(slug);
if (!isGloballyEnabled) return [];
const rows = await this.prismaClient.teamFeatures.findMany({
where: { featureId: slug },
select: { teamId: true },
orderBy: { teamId: "asc" },
});
return rows.map((r) => r.teamId);
} catch (err) {
captureException(err);
throw err;
}
}
}