Skip to content

[LIMITATION] Feature: allow multiple Limiters with different configurations#292

Open
GreeFine wants to merge 16 commits into
actix:mainfrom
GreeFine:master
Open

[LIMITATION] Feature: allow multiple Limiters with different configurations#292
GreeFine wants to merge 16 commits into
actix:mainfrom
GreeFine:master

Conversation

@GreeFine

@GreeFine GreeFine commented Oct 4, 2022

Copy link
Copy Markdown
Contributor

PR Type

Feature

PR Checklist

  • Tests for the changes have been added / updated.
  • Documentation comments have been added / updated.
  • A changelog entry has been made for the appropriate packages.
  • Format code with the nightly rustfmt (cargo +nightly fmt).

Overview

Currently I can declare and use only one Limiter who can hold one configuration
This PR adds the possibility to create a multitude of Limiter so we can have different configurations

Note

I added a method to build the Limiter with an already existing Client (builder_with_redis_client) to prevent re-creating a new client for each new Limiter
I don't actually know if this was a good idea and is making any performance improvements. And I didn't have the time to test it

@robjtede robjtede added B-semver-minor A-limitation Project: actix-limitation labels Oct 16, 2022

@JohnTitor JohnTitor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late review.
At a quick glance, I think the current has some issues and there could be a better approach.

pub struct RateLimiter {
/// Used to define multiple limiter, with different configurations
///
/// WARNING: When used (not None) the middleware will expect a `HashMap<Limiter>` in the actix-web `app_data`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't match with the implementation.

limiters
.get(scope)
.unwrap_or_else(|| panic!("Unable to find defined limiter with scope: {}", scope))
.clone()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how it's expensive to clone on each request, we should ensure it before merging.

@GreeFine

Copy link
Copy Markdown
Contributor Author

Sorry for the late review. At a quick glance, I think the current has some issues and there could be a better approach.

No worries, thanks for the review !
To be honest I was using it a lot in my previous company but not anymore.
Unless anyone need it, or you think it would be a good addition, We can close this PR.

I don't want to spend time on something that is not going to be used, but otherwise I will gladly take another go at this :)

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

Labels

A-limitation Project: actix-limitation B-semver-minor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants