Skip to content

Commit

Permalink
Fixing exception around multiple feeds during Google Reader import pr…
Browse files Browse the repository at this point in the history
…ocess. Also switching rate limit to status code 429.
  • Loading branch information
samuelclay committed Dec 18, 2011
1 parent 778a5b7 commit a47d121
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
8 changes: 6 additions & 2 deletions apps/feed_import/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion apps/reader/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions utils/ratelimit.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit a47d121

Please sign in to comment.