Skip to content

feat(links): enforce per-user link limit to prevent unbounded link creation and database abuse#343

Open
Rishikapurbey wants to merge 2 commits into
vishnukothakapu:mainfrom
Rishikapurbey:feat/per-user-link-limit
Open

feat(links): enforce per-user link limit to prevent unbounded link creation and database abuse#343
Rishikapurbey wants to merge 2 commits into
vishnukothakapu:mainfrom
Rishikapurbey:feat/per-user-link-limit

Conversation

@Rishikapurbey

Copy link
Copy Markdown
Contributor

Summary

Adds a configurable per-user link limit to prevent unbounded link creation and protect database performance.

Problem

Previously there was no cap on how many links a user could add. An authenticated user could programmatically create unlimited links causing:

  • Unbounded database growth per user
  • Public profile pages rendering thousands of link rows causing slow load times
  • Performance degradation for all users sharing the same database

Note: The existing rate limiting restricts the speed of creation but not the total count.

Changes Made

app/api/links/route.ts

  • Added MAX_LINKS_PER_USER = 20 configurable constant
  • Added _count: { id: true } to the existing aggregate query inside the transaction — no extra DB call needed
  • Added atomic limit check inside the Prisma transaction to prevent race conditions where two simultaneous requests could both pass the check
  • Added LINK_LIMIT_REACHED error handler returning a clear user-facing message

How It Works

```ts
const MAX_LINKS_PER_USER = 20;

const maxOrder = await tx.link.aggregate({
where: { userId: user.id },
_max: { position: true },
_count: { id: true }, // get count in same query — no extra DB call
});

if ((maxOrder._count.id ?? 0) >= MAX_LINKS_PER_USER) {
throw Object.assign(new Error("LINK_LIMIT_REACHED"), { code: "LINK_LIMIT_REACHED" });
}
```

Error Response

When limit is reached:
```json
{ "error": "You can add a maximum of 20 links." }
```
Status: 400 Bad Request

Files Affected

  • app/api/links/route.ts

Related Issue

Closes #331

@vercel

vercel Bot commented Jun 20, 2026

Copy link
Copy Markdown

@Rishikapurbey is attempting to deploy a commit to the vishnukothakapu's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@Rishikapurbey, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 23 minutes and 54 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 84595287-31b0-44aa-bd55-c2d478e3a9cf

📥 Commits

Reviewing files that changed from the base of the PR and between 38d0dc7 and cd280b7.

📒 Files selected for processing (1)
  • app/api/links/route.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@vercel

vercel Bot commented Jun 20, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
linkid Ready Ready Preview, Comment Jun 20, 2026 10:29am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT] Add per-user link limit to prevent unbounded link creation and database abuse

2 participants