perf: use repository for apiKeys list query & caching in /settings/developer/api-keys RSC (#21776)

This commit is contained in:
Amit Sharma authored and GitHub committed 2025-06-12 21:11:06 +00:00
1 parent cbb020911d
commit e6497c87ca
4 files changed
+50 -23

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
import prisma from "@calcom/prisma";
export class ApiKeyRepository {
static async findApiKeysFromUserId({ userId }: { userId: number }) {
return await prisma.apiKey.findMany({
where: {
userId,
OR: [
{
NOT: {
appId: "zapier",
},
},
{
appId: null,
},
],
},
orderBy: { createdAt: "desc" },
});
}
}
@@ -1,4 +1,4 @@
import prisma from "@calcom/prisma";
import { ApiKeyRepository } from "@calcom/lib/server/repository/apiKey";
import type { TrpcSessionUser } from "../../../types";
@@ -9,20 +9,5 @@ type ListOptions = {
};
export const listHandler = async ({ ctx }: ListOptions) => {
return await prisma.apiKey.findMany({
where: {
userId: ctx.user.id,
OR: [
{
NOT: {
appId: "zapier",
},
},
{
appId: null,
},
],
},
orderBy: { createdAt: "desc" },
});
return ApiKeyRepository.findApiKeysFromUserId({ userId: ctx.user.id });
};