Permalink
Browse files

Fixing exception around multiple feeds during Google Reader import pr…

…ocess. Also switching rate limit to status code 429.
  • Loading branch information...
1 parent 778a5b7 commit a47d1211c0f75200abe816c0399276c125bfaacd @samuelclay committed Dec 18, 2011
Showing with 9 additions and 5 deletions.
  1. +6 −2 apps/feed_import/models.py
  2. +1 −1 apps/reader/views.py
  3. +2 −2 utils/ratelimit.py
@@ -229,8 +229,12 @@ def process_item(self, item, folders):
feed_data = dict(feed_address=feed_address, feed_link=feed_link, feed_title=feed_title)
feed_data['active_subscribers'] = 1
feed_data['num_subscribers'] = 1
- feed_db, _ = Feed.objects.get_or_create(feed_address=feed_address,
- defaults=dict(**feed_data))
+ feeds = Feed.objects.filter(feed_address=feed_address,
+ branch_from_feed__isnull=True).order_by('-num_subscribers')
+ if feeds:
+ feed_db = feeds[0]
+ else:
+ feed_db = Feed.objects.create(**feed_data)
us, _ = UserSubscription.objects.get_or_create(
feed=feed_db,
@@ -154,7 +154,7 @@ def autologin(request, username, secret):
return HttpResponseRedirect(reverse('index') + next)
-@ratelimit(minutes=1, requests=20)
+@ratelimit(minutes=1, requests=12)
@json.json_view
def load_feeds(request):
user = get_user(request)
View
@@ -1,4 +1,4 @@
-from django.http import HttpResponseForbidden
+from django.http import HttpResponse
from django.core.cache import cache
from datetime import datetime, timedelta
import functools
@@ -85,7 +85,7 @@ def key_extra(self, request):
def disallowed(self, request):
"Over-ride this method if you want to log incidents"
- return HttpResponseForbidden('Rate limit exceeded')
+ return HttpResponse('Rate limit exceeded', status=429)
def expire_after(self):
"Used for setting the memcached cache expiry"

0 comments on commit a47d121

Please sign in to comment.