Giter Club home page Giter Club logo

Comments (7)

stefanprodan avatar stefanprodan commented on May 8, 2024

Yes setting the defaults to 0 should work, the default values supplied in the constructor applies to actions that don't have the EnableThrottling attribute, or when you've missed to supply a PerFoo rate in the attribute.
So if the default policy has a perDay limit, and the EnableThrottling doesn't have it, then the perDay limit from ThrottlePolicy constructor will be used.
If all your action have EnableThrottling with every PerX specified then none of the constructor values will apply.

from mvcthrottle.

migig avatar migig commented on May 8, 2024

Okay that makes good sense.

But what happens, for example, if I want to throttle an action by day. In the attribute, is it enough to specify [EnableThrottling(PerDay = 123)], or must I also specify for PerSecond = and PerHour = as well - to override the 0 value in the defaults?

from mvcthrottle.

stefanprodan avatar stefanprodan commented on May 8, 2024

No need to specify those. You need to put the rate types you want to enable in the constructor and use them in attribute. The 0 value should disable the rate limit type, please make a test and let me know.

from mvcthrottle.

migig avatar migig commented on May 8, 2024

"You need to put the rate types you want to enable in the constructor"... I assume you mean the ctor of the global filter. It's for a big project, so we "enabled" all of them to 0.

Okay I tested and it seems to work, but we have many places where it's used, and I'm trying to go through many combinations to see what happens.

from mvcthrottle.

migig avatar migig commented on May 8, 2024

It's a pity this isn't on the main docs, so for anybody else who wants to know, here is my understanding:

  • The global filter takes rate limits. These are the defaults.
  • The defaults are used if you don't specify custom rate limits in the [EnableThrottling] attribute.
  • There are various ways to do throttling. If you prefer to specify custom limits on your attributes, and never rely on defaults, then you must set 0 as the default for all rate limits. So you do this: Policy = new ThrottlePolicy(perSecond:0, perMinute:0, perHour:0, perDay:0, perWeek:0) { .... Then specify a rate limit in the attribute, for example: [EnableThrottling(PerHour = 10)].
  • If you take this approach, then the custom rate limits will override the defaults. But also, if your attribute is for e.g. [EnableThrottling(PerHour = 10)] then it not only overrides the perHour: default, but also ignores the perSecond: and perMinute: defaults. This means you don't need to specify custom values for all limits, only the one you are interested in. You don't need to do this: [EnableThrottling(PerSecond = x, PerMinute = y, PerHour = 10)].

Please correct anything if it's wrong? I'll update more when I have tested more.

from mvcthrottle.

stefanprodan avatar stefanprodan commented on May 8, 2024

You are right, this is the intended behavior. I must find a better way to enable/disable limit types.
If you don't specify a rate limit type when you register the filter, even if you specified that type in the attribute it will get ignored.

ThrottlePolicy(perSecond:0, perMinute:0)
[EnableThrottling(PerHour = 10)]

In the example above, PerHour will get ignored.

Thanks for running these tests.

from mvcthrottle.

migig avatar migig commented on May 8, 2024

Oops, so I misunderstood... 😄

In your example I thought the PerHour will be used, but you say it will be ignored (because it has no corresponding default in the filter). So that means that there will be "maximum" throttling for that attribute, because PerHour is ignored, and everything else is 0?

Sorry, I am maybe a bit "slow" (I've been throttled)...

I agree we should think what is a good way to handle this use case. Or keep it as it is, but make a "formal" documentation for it...

from mvcthrottle.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.