add throttle for autosuggest api
This commit is contained in:
Родитель
56b16262e9
Коммит
0306b7fc14
|
@ -1266,16 +1266,18 @@ class SearchTest(ESTestCase):
|
|||
eq_(data['name'], a.name)
|
||||
eq_(data['rating'], a.average_rating)
|
||||
|
||||
def test_category_suggestions(self):
|
||||
cat = Category.objects.get(slug='feeds')
|
||||
def test_no_category_suggestions(self):
|
||||
response = self.client.get(
|
||||
'/en-US/firefox/api/%.1f/search_suggestions/?q=Feed' %
|
||||
api.CURRENT_VERSION)
|
||||
data = json.loads(response.content)['suggestions'][0]
|
||||
eq_(data['id'], cat.pk)
|
||||
eq_(data['name'], cat.name)
|
||||
assert 'rating' not in data
|
||||
eq_(json.loads(response.content)['suggestions'], [])
|
||||
|
||||
def test_suggestions_throttle(self):
|
||||
self.create_sample('autosuggest-throttle')
|
||||
response = self.client.get(
|
||||
'/en-US/firefox/api/%.1f/search_suggestions/?q=delicious' %
|
||||
api.CURRENT_VERSION)
|
||||
eq_(response.status_code, 503)
|
||||
|
||||
class LanguagePacks(UploadTest):
|
||||
fixtures = ['addons/listed', 'base/apps', 'base/platforms']
|
||||
|
|
|
@ -393,17 +393,17 @@ class SearchView(APIView):
|
|||
|
||||
@json_view
|
||||
def search_suggestions(request):
|
||||
if waffle.sample_is_active('autosuggest-throttle'):
|
||||
return HttpResponse(status=503)
|
||||
cat = request.GET.get('cat', 'all')
|
||||
suggesterClass = {
|
||||
'all': AddonSuggestionsAjax,
|
||||
'themes': PersonaSuggestionsAjax,
|
||||
}.get(cat, AddonSuggestionsAjax)
|
||||
suggester = suggesterClass(request, ratings=True)
|
||||
suggs = _build_suggestions(request, cat, suggester)
|
||||
for s in suggs:
|
||||
if 'rating' in s:
|
||||
s['rating'] = float(s['rating'])
|
||||
return {'suggestions': suggs}
|
||||
items = suggesterClass(request, ratings=True).items
|
||||
for s in items:
|
||||
s['rating'] = float(s['rating'])
|
||||
return {'suggestions': items}
|
||||
|
||||
|
||||
class ListView(APIView):
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
INSERT INTO waffle_sample_amo (name, percent, note)
|
||||
VALUES ('autosuggest-throttle', 0.0, 'Percentage of search autosuggest API requests to ignore');
|
Загрузка…
Ссылка в новой задаче