Coder Social home page Coder Social logo

Comments (6)

markotibold avatar markotibold commented on May 23, 2024

implemented in the permission module. Plus wrote a test. Both test and implementation need refactoring.

from django-rest-framework.

tomchristie avatar tomchristie commented on May 23, 2024

I would probably store it based on the name of the Resource class.
Actually even better would be if the throttle has a get_cache_key() method.
For per-user it'd return the user id, for the per-resource it'd return the
Resource class name - then have both Thottle classes inherit from a
BaseThrottle class. Then it's super obvious and easy for anyone to provide
for alternative caching behavior.
Actually thinking about it there's a few ways that a BaseThrottle class
could be made easier to override.

I think it's refactor nicely to:

BaseThrottle(BasePermission):
get_cache_key(self) # Not Implemented
check_throttle(self, cache_key)
throttle_success(self, cache_key)
throttle_failure(self, cache_key)

PerUserThrottle(BaseThrottle):
get_cache_key(self)

PerResourceThrottle(BaseThrottle):
get_cache_key(self)

Also thinking about it I think it'd be nice if the .throttle attribute was
string like '10/sec', '45/min', '100/hour', '100/day', '10/s' '45/m' etc...
instead of being a 2-tuple

So something like:

num, period = getattr(self.view, 'throttle', '0/sec').partition('/')
num = int(num)
period = {'s': 1, 'm': 60, 'h': 3600, 'd': 86400}[period[0]]

On 11 June 2011 01:22, markotibold <
[email protected]>wrote:

It would be nice to be able to throttle requests to a resource, not only
per user. Only question is: should we store the throttle in the cache
based on the url of the resource or based on the View's class....

Reply to this email directly or view it on GitHub:
#25

from django-rest-framework.

markotibold avatar markotibold commented on May 23, 2024

Yeah that's a good idea!

But to return self.view.resource.__class__.__name__ in the gey_cache_key() method would imply the View actually has a resource set. But this is not necessarily the case. We can have it store the name of the view then instead. Any thoughts?

from django-rest-framework.

tomchristie avatar tomchristie commented on May 23, 2024

Fair point. Would be fine yeah. Call it PerViewThrottling tho' ;)

from django-rest-framework.

markotibold avatar markotibold commented on May 23, 2024

Ok, I got it all implemented and tested. Check out my latest commits. Did
some proper refactoring on last nights work.

Cheers,

Mako

On 11 June 2011 19:44, tomchristie <
[email protected]>wrote:

Fair point. Would be fine yeah. Call it PerViewThrottling tho' ;)

Reply to this email directly or view it on GitHub:

#25 (comment)

from django-rest-framework.

tomchristie avatar tomchristie commented on May 23, 2024

Oops, ignore my latest github ticket then :)
Nice work.
I'll pull this bit in tomorrow...

On 11 June 2011 19:36, markotibold <
[email protected]>wrote:

Ok, I got it all implemented and tested. Check out my latest commits. Did
some proper refactoring on last nights work.

Cheers,

Mako

On 11 June 2011 19:44, tomchristie <
[email protected]>wrote:

Fair point. Would be fine yeah. Call it PerViewThrottling tho' ;)

Reply to this email directly or view it on GitHub:

#25 (comment)

Reply to this email directly or view it on GitHub:

#25 (comment)

from django-rest-framework.

Related Issues (20)

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.