Skip to content

Add index for rate limit cleanup queries - #436

Open
wakevro wants to merge 1 commit into
convex:mainfrom
wakevro:fix/rate-limit-cleanup-index
Open

wakevro wants to merge 1 commit into
convex:mainfrom
wakevro:fix/rate-limit-cleanup-index

Conversation

@wakevro

@wakevro wakevro commented Sep 2, 2026

Copy link
Copy Markdown

Add an index on rateLimit.lastRequest so expired rate-limit records can be deleted using an indexed range query.

Problem

Convex currently reports the following warning during rate-limit cleanup:

[CONVEX M(adapter:deleteMany)] [WARN] Querying without an index on table "rateLimit".
This can cause performance issues, and may hit the document read limit.
To fix, add an index that begins with the following fields in order:
[lastRequest]

The cleanup operation filters expired rate-limit records by lastRequest, but the rateLimit table only has an index on key.

Changes

  • Add the lastRequest index to the schema generator
  • Update the checked-in component schema
  • Add regression coverage for generated schemas
  • Verify that runtime cleanup deletes expired records without an unindexed-query warning
  • Verify that non-expired records are preserved

Testing

  • npm run build
  • npm run typecheck
  • npm run test
  • npm run lint

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@vercel

vercel Bot commented Sep 2, 2026

Copy link
Copy Markdown

@wakevro is attempting to deploy a commit to the Convex Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Sep 2, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: get-convex/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: 12b33f88-ce60-4735-93f1-319a902a8b24

📥 Commits

Reviewing files that changed from the base of the PR and between 2f9fcf6 and 34d1ea1.

📒 Files selected for processing (4)
  • src/client/create-schema.test.ts
  • src/client/create-schema.ts
  • src/client/rate-limit-index.test.ts
  • src/component/schema.ts

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The rate-limit schema now includes a lastRequest index in both schema generation and table definitions. Tests verify that schema generation emits the index. A cleanup test inserts expired and current records, runs adapter:deleteMany with a lastRequest < 200 filter, and confirms that only the expired record is removed without a console warning.

Merge Risk: ⚪ Minimal · up to 34d1e

This change adds an index for existing rate-limit cleanup queries without changing which records are deleted or introducing new runtime or permission paths. No actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding an index for rate-limit cleanup queries.
Description check ✅ Passed The description directly explains the index change, its purpose, implementation updates, regression coverage, and testing.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

Some tools did not complete. Review the errors below.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/client/create-schema.test.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

src/client/create-schema.ts

ESLint skipped: the matched ESLint configuration already failed (missing-dependency).

src/client/rate-limit-index.test.ts

ESLint skipped: the matched ESLint configuration already failed (missing-dependency).

  • 1 others

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.

helixnebulatech added a commit to helixnebulatech/convex-better-auth that referenced this pull request Oct 8, 2026
Better Auth 1.7 database rate limiting prunes rows with
deleteMany(rateLimit where lastRequest < cutoff) whenever a window
resets. Without an index starting with lastRequest the adapter scanned
the whole rateLimit table and logged "Querying without an index".

Add the index to the schema generator and the shipped component
schema, and test that the shipped schema matches the generator output.

Port of convex#436.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant