Fixing rate limit on saved stories so that reading standard feeds doesn't impact the rate limits on saved stories.

This commit is contained in:
Samuel Clay 2025-04-11 11:42:14 -07:00
parent 4d8cae43a0
commit 45331c005b
3 changed files with 11 additions and 2 deletions

View file

@ -8,7 +8,9 @@
- `make log` - View logs
- `make lint` - Run linting (isort, black, flake8)
- `make test` - Run all tests
- Run single test: `docker exec -it newsblur_web python3 manage.py test apps.path.to.test.TestClass.test_method -v 3`
- Run single test: `docker exec -t newsblur_web python3 manage.py test apps.path.to.test.TestClass.test_method -v 3`
Note: All docker commands must use `-t` instead of `-it` to avoid interactive mode issues when running through Claude.
## Code Style
- **Python**:

View file

@ -1035,7 +1035,7 @@ def load_feed_page(request, feed_id):
return HttpResponse(data, content_type="text/html; charset=utf-8")
@ratelimit(minutes=5, requests=50)
@ratelimit(minutes=5, requests=50, use_path=True)
@json.json_view
def load_starred_stories(request):
user = get_user(request)

View file

@ -11,6 +11,7 @@ class ratelimit(object):
# This class is designed to be sub-classed
minutes = 1 # The time period
requests = 4 # Number of allowed requests in that time period
use_path = False # Whether to include the request path in the key
prefix = "rl-" # Prefix for memcache key
@ -77,6 +78,12 @@ class ratelimit(object):
key = request.COOKIES.get("newsblur_sessionid", "")
if not key:
key = request.META.get("HTTP_USER_AGENT", "")
# Add request path to the key if use_path is enabled
if getattr(self, 'use_path', False):
path = request.path
key = f"{key}-{path}"
return key
def disallowed(self, request):