Skip to content

Conversation

@arcoraven
Copy link
Contributor

@arcoraven arcoraven commented Apr 15, 2025

Updates the rate limit to use a sliding window


PR-Codex overview

This PR focuses on updating the rate limiting mechanism in the rateLimit function to use a sliding window approach instead of a fixed window, enhancing the accuracy of request counting over a 10-second interval.

Detailed summary

  • Renamed RATE_LIMIT_WINDOW_SECONDS to SLIDING_WINDOW_SECONDS.
  • Replaced fixed window logic with sliding window logic for request counting.
  • Updated the rateLimit function to calculate total requests over the last 10 seconds.
  • Modified Redis interactions to use mget for batch retrieval of request counts.
  • Adjusted test cases to reflect the new sliding window behavior.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

@arcoraven arcoraven requested a review from a team as a code owner April 15, 2025 09:19
@changeset-bot
Copy link

changeset-bot bot commented Apr 15, 2025

🦋 Changeset detected

Latest commit: 6d1aebd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@thirdweb-dev/service-utils Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Apr 15, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 15, 2025 9:37am
login ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 15, 2025 9:37am
thirdweb_playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 15, 2025 9:37am
thirdweb-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 15, 2025 9:37am
wallet-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 15, 2025 9:37am

@graphite-app
Copy link
Contributor

graphite-app bot commented Apr 15, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

@codecov
Copy link

codecov bot commented Apr 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 54.76%. Comparing base (185d2f3) to head (ec099a7).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6730   +/-   ##
=======================================
  Coverage   54.76%   54.76%           
=======================================
  Files         894      894           
  Lines       56201    56201           
  Branches     3820     3820           
=======================================
  Hits        30780    30780           
  Misses      25326    25326           
  Partials       95       95           
Flag Coverage Δ
packages 54.76% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Contributor

github-actions bot commented Apr 15, 2025

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 49.91 KB (0%) 999 ms (0%) 280 ms (+200.21% 🔺) 1.3 s
thirdweb (cjs) 136.37 KB (0%) 2.8 s (0%) 399 ms (+49.11% 🔺) 3.2 s
thirdweb (minimal + tree-shaking) 5.63 KB (0%) 113 ms (0%) 135 ms (+1679.21% 🔺) 248 ms
thirdweb/chains (tree-shaking) 514 B (0%) 11 ms (0%) 99 ms (+2935.28% 🔺) 109 ms
thirdweb/react (minimal + tree-shaking) 19.35 KB (0%) 388 ms (0%) 117 ms (+704.42% 🔺) 504 ms

@graphite-app
Copy link
Contributor

graphite-app bot commented Apr 15, 2025

Merge activity

Updates the rate limit to use a sliding window

<!-- start pr-codex -->

---

## PR-Codex overview
This PR focuses on updating the rate limiting functionality in the `rateLimit` function to utilize a sliding window approach instead of a fixed window, enhancing how requests are counted over time.

### Detailed summary
- Renamed `RATE_LIMIT_WINDOW_SECONDS` to `SLIDING_WINDOW_SECONDS`.
- Modified Redis interaction to use `mget` for batch fetching request counts.
- Updated the logic to calculate total requests over the last 10 seconds.
- Removed `sampleRate` handling and its related logic.
- Changed error messages for exceeding rate limits.
- Adjusted tests to align with the new sliding window logic.

> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}`

<!-- end pr-codex -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-queue Adds the pull request to Graphite's merge queue. packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants