avoid high cpu load for invalid range request

This commit is contained in:
j 2016-03-17 15:44:06 +01:00
parent 2ee8249cd5
commit 8c23d73bd3
2 changed files with 7 additions and 1 deletions

View file

@ -9,13 +9,13 @@ from sqlalchemy.sql.expression import text
from sqlalchemy import func from sqlalchemy import func
from oxtornado import actions from oxtornado import actions
import utils #utils must be imported before websocket to avoid loop
from websocket import trigger_event from websocket import trigger_event
import meta import meta
from . import models from . import models
from . import query from . import query
import settings import settings
import state import state
import utils
from . import person_api from . import person_api
from . import title_api from . import title_api

View file

@ -10,6 +10,9 @@ from . import models
import settings import settings
import utils import utils
import logging
logger = logging.getLogger(__name__)
def parse(data): def parse(data):
query = {} query = {}
query['range'] = [0, 100] query['range'] = [0, 100]
@ -18,6 +21,9 @@ def parse(data):
for key in ('keys', 'group', 'list', 'range', 'sort', 'query'): for key in ('keys', 'group', 'list', 'range', 'sort', 'query'):
if key in data: if key in data:
query[key] = data[key] query[key] = data[key]
if [r for r in query['range'] if not isinstance(r, int)]:
logger.error('range must be 2 integers! got this: %s', query['range'])
query['range'] = [0, 0]
#print data #print data
query['qs'] = models.Item.find(data) query['qs'] = models.Item.find(data)
if not 'group' in query: if not 'group' in query: