Skip to content

Commit bccf63f

Browse files
committed
chore: temp rate limit viewPost
1 parent 1451fdb commit bccf63f

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

src/directive/rateLimit.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ const keyGenerator: RateLimitKeyGenerator<Context> = (
5959
return `${context.userId ?? context.trackingId}:createComment`;
6060
case 'parseOpportunity':
6161
return `${context.userId ?? context.trackingId}:parseOpportunity`;
62+
case 'viewPost':
63+
return `${context.userId ?? context.trackingId}:viewPost`;
6264
case 'sentimentTimeSeries':
6365
case 'sentimentHighlights':
6466
return `${context.userId ?? context.trackingId ?? context.req.ip}:sentiment`;
@@ -110,6 +112,11 @@ export const onLimit: RateLimitOnLimit<Context> = (
110112
throw new RateLimitError({
111113
message: `You tried to parse job too many times. Try again in ${period} or contact team for assistance.`,
112114
});
115+
case 'viewPost':
116+
counters?.api?.rateLimit?.add(1, { type: 'viewPost' });
117+
throw new RateLimitError({
118+
message: 'Post views are temporarily rate-limited',
119+
});
113120
case 'sentimentTimeSeries':
114121
case 'sentimentHighlights':
115122
counters?.api?.rateLimit?.add(1, { type: 'sentiment' });

src/schema/posts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1709,7 +1709,7 @@ export const typeDefs = /* GraphQL */ `
17091709
Post to share in the source
17101710
"""
17111711
id: ID!
1712-
): EmptyResponse @auth
1712+
): EmptyResponse @auth @rateLimit(limit: 50, duration: 3600)
17131713
17141714
"""
17151715
Dismiss user post feedback

0 commit comments

Comments
 (0)