mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 11:05:54 +01:00 
			
		
		
		
	check keys
This commit is contained in:
		| @@ -1,5 +1,7 @@ | |||||||
| "use strict"; | "use strict"; | ||||||
|  |  | ||||||
|  | var winston = require('winston'); | ||||||
|  |  | ||||||
| module.exports = function(db, module) { | module.exports = function(db, module) { | ||||||
| 	var helpers = module.helpers.mongo; | 	var helpers = module.helpers.mongo; | ||||||
|  |  | ||||||
| @@ -23,6 +25,7 @@ module.exports = function(db, module) { | |||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
| 	module.getObjects = function(keys, callback) { | 	module.getObjects = function(keys, callback) { | ||||||
|  | 		helpers.checkKeys(keys); | ||||||
| 		db.collection('objects').find({_key: {$in: keys}}, {_id: 0}).toArray(function(err, data) { | 		db.collection('objects').find({_key: {$in: keys}}, {_id: 0}).toArray(function(err, data) { | ||||||
| 			if(err) { | 			if(err) { | ||||||
| 				return callback(err); | 				return callback(err); | ||||||
| @@ -53,6 +56,7 @@ module.exports = function(db, module) { | |||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
| 	module.getObjectsFields = function(keys, fields, callback) { | 	module.getObjectsFields = function(keys, fields, callback) { | ||||||
|  | 		helpers.checkKeys(keys); | ||||||
| 		var _fields = { | 		var _fields = { | ||||||
| 			_id: 0, | 			_id: 0, | ||||||
| 			_key: 1 | 			_key: 1 | ||||||
|   | |||||||
| @@ -1,6 +1,7 @@ | |||||||
| "use strict"; | "use strict"; | ||||||
|  |  | ||||||
| var helpers = {}; | var helpers = {}, | ||||||
|  | 	winston = require('winston'); | ||||||
|  |  | ||||||
| helpers.toMap = function(data) { | helpers.toMap = function(data) { | ||||||
| 	var map = {}; | 	var map = {}; | ||||||
| @@ -33,4 +34,16 @@ helpers.valueToString = function(value) { | |||||||
|  |  | ||||||
| helpers.noop = function() {}; | helpers.noop = function() {}; | ||||||
|  |  | ||||||
|  | helpers.checkKeys = function(keys) { | ||||||
|  | 	if (!Array.isArray(keys)) { | ||||||
|  | 		var e = new Error('invalid keys'); | ||||||
|  | 		winston.warn('[INVALID_KEYS] ',  e.stack); | ||||||
|  | 		return; | ||||||
|  | 	} | ||||||
|  | 	if (keys.length >= 50) { | ||||||
|  | 		var e = new Error('too many keys'); | ||||||
|  | 		winston.warn('[TOO_MANY_KEYS] ' + keys.length + ' ' + keys[0] + '  ' + keys[keys.length - 1] + '\n', e.stack); | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
| module.exports = helpers; | module.exports = helpers; | ||||||
		Reference in New Issue
	
	Block a user