Limiting how many results try to get fetched on admin DB searches like /db/user so that we don't blow up the DB.

This commit is contained in:
Nick Winter 2015-02-18 14:12:23 -08:00
parent f2a5c4bc5a
commit 880d22ed50

View file

@ -187,14 +187,17 @@ module.exports = class Handler
# Conditions are chained query functions, for example: query.find().limit(20).sort('-dateCreated') # Conditions are chained query functions, for example: query.find().limit(20).sort('-dateCreated')
conditions = JSON.parse(req.query.conditions || '[]') conditions = JSON.parse(req.query.conditions || '[]')
hasLimit = false
try try
for condition in conditions for condition in conditions
name = condition[0] name = condition[0]
f = query[name] f = query[name]
args = condition[1..] args = condition[1..]
query = query[name](args...) query = query[name](args...)
hasLimit ||= f is 'limit'
catch e catch e
return @sendError(res, 422, 'Badly formed conditions.') return @sendError(res, 422, 'Badly formed conditions.')
query.limit(2000) unless hasLimit
query.exec (err, documents) => query.exec (err, documents) =>
return @sendDatabaseError(res, err) if err return @sendDatabaseError(res, err) if err