fix: ratelimit - updates (#10347)

pull/10251/head^2
sean-brydon 2023-07-27 09:41:43 +01:00 committed by GitHub
parent 4f488be654
commit 8cdddfa1d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 1 deletions

View File

@ -7,7 +7,7 @@ import logger from "./logger";
const log = logger.getChildLogger({ prefix: ["RateLimit"] });
export type RateLimitHelper = {
rateLimitingType?: "core" | "forcedSlowMode";
rateLimitingType?: "core" | "forcedSlowMode" | "common";
identifier: string;
};
@ -57,6 +57,12 @@ export function rateLimiter() {
prefix: "ratelimit",
limiter: Ratelimit.fixedWindow(10, "60s"),
}),
common: new Ratelimit({
redis,
analytics: true,
prefix: "ratelimit",
limiter: Ratelimit.fixedWindow(200, "60s"),
}),
forcedSlowMode: new Ratelimit({
redis,
analytics: true,

View File

@ -2,6 +2,7 @@ import { type PrismaClient, Prisma } from "@prisma/client";
import { orderBy } from "lodash";
import { hasFilter } from "@calcom/features/filters/lib/hasFilter";
import { checkRateLimitAndThrowError } from "@calcom/lib/checkRateLimitAndThrowError";
import { CAL_URL } from "@calcom/lib/constants";
import { markdownToSafeHTML } from "@calcom/lib/markdownToSafeHTML";
import { getBookerUrl } from "@calcom/lib/server/getBookerUrl";
@ -78,6 +79,11 @@ export const compareMembership = (mship1: MembershipRole, mship2: MembershipRole
export const getByViewerHandler = async ({ ctx, input }: GetByViewerOptions) => {
const { prisma } = ctx;
await checkRateLimitAndThrowError({
identifier: `eventTypes:getByViewer:${ctx.user.id}`,
rateLimitingType: "common",
});
const user = await prisma.user.findUnique({
where: {
id: ctx.user.id,

View File

@ -1,3 +1,4 @@
import { checkRateLimitAndThrowError } from "@calcom/lib/checkRateLimitAndThrowError";
import { prisma } from "@calcom/prisma";
import type { TrpcSessionUser } from "../../../trpc";
@ -9,6 +10,10 @@ type ListOptions = {
};
export const listHandler = async ({ ctx }: ListOptions) => {
await checkRateLimitAndThrowError({
identifier: `eventTypes:list:${ctx.user.id}`,
rateLimitingType: "common",
});
return await prisma.eventType.findMany({
where: {
userId: ctx.user.id,