Skip to content

Conversation

@jnsdls
Copy link
Member

@jnsdls jnsdls commented Apr 22, 2025

Expose rateLimitSlidingWindow Strategy for Low-Level Usage

This PR refactors the rate limiting implementation in @thirdweb-dev/service-utils to expose the rateLimitSlidingWindow strategy directly for more low-level usage. The changes include:

  • Extracting the sliding window rate limiting logic into a separate strategy module
  • Creating shared types for Redis interface and rate limit results
  • Exposing the rateLimitSlidingWindow function in the package exports
  • Improving the key naming convention for rate limit cache entries
  • Maintaining backward compatibility with existing rate limit functionality

These changes allow for more flexible and direct usage of the rate limiting strategy in various contexts.


PR-Codex overview

This PR introduces a new rateLimitSlidingWindow strategy for more granular rate limiting control and refactors the existing rate limiting logic to utilize this new strategy. It enhances the usability of the rate limiting feature by providing a direct export and improving type definitions.

Detailed summary

  • Added direct export of rateLimitSlidingWindow from ./core/rateLimit/strategies/sliding-window.js.
  • Introduced IRedis type for Redis interface in shared.ts.
  • Refactored rate limiting logic in rateLimit to use rateLimitSlidingWindow.
  • Updated request counting logic and key formatting in sliding-window.ts.
  • Improved test cases to reflect changes in request counting and key structure.

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

@vercel
Copy link

vercel bot commented Apr 22, 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 22, 2025 4:56pm
login ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 22, 2025 4:56pm
thirdweb_playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 22, 2025 4:56pm
thirdweb-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 22, 2025 4:56pm
wallet-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 22, 2025 4:56pm

@changeset-bot
Copy link

changeset-bot bot commented Apr 22, 2025

🦋 Changeset detected

Latest commit: 12ab488

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

Copy link
Member Author

jnsdls commented Apr 22, 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.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@codecov
Copy link

codecov bot commented Apr 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 55.18%. Comparing base (c03734a) to head (12ab488).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6815   +/-   ##
=======================================
  Coverage   55.18%   55.18%           
=======================================
  Files         896      896           
  Lines       56940    56940           
  Branches     3943     3943           
=======================================
  Hits        31420    31420           
  Misses      25424    25424           
  Partials       96       96           
Flag Coverage Δ
packages 55.18% <ø> (ø)
🚀 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 22, 2025

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 50.73 KB (0%) 1.1 s (0%) 193 ms (+105.05% 🔺) 1.3 s
thirdweb (cjs) 138.79 KB (0%) 2.8 s (0%) 367 ms (+52.19% 🔺) 3.2 s
thirdweb (minimal + tree-shaking) 5.6 KB (0%) 113 ms (0%) 92 ms (+958.71% 🔺) 204 ms
thirdweb/chains (tree-shaking) 514 B (0%) 11 ms (0%) 36 ms (+569.42% 🔺) 46 ms
thirdweb/react (minimal + tree-shaking) 19.41 KB (0%) 389 ms (0%) 96 ms (+442.39% 🔺) 484 ms

@jnsdls jnsdls force-pushed the Expose_rateLimitSlidingWindow_strategy_for_low-level_usage branch from f614c06 to 12ab488 Compare April 22, 2025 16:49
@jnsdls jnsdls merged commit 69ec6e0 into main Apr 22, 2025
24 checks passed
@jnsdls jnsdls deleted the Expose_rateLimitSlidingWindow_strategy_for_low-level_usage branch April 22, 2025 21:11
@joaquim-verges joaquim-verges mentioned this pull request Apr 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants