From fe58ea55d47be76d22b4a13be62ce44e602a6862 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Sat, 6 Sep 2014 20:47:20 -0400 Subject: [PATCH] moved debugs 1 level up increased key limit to 100 --- src/database/mongo/hash.js | 11 +++++++++-- src/database/mongo/helpers.js | 14 ++------------ src/database/mongo/sets.js | 4 ++++ 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/database/mongo/hash.js b/src/database/mongo/hash.js index 08daf12322..1512fbec20 100644 --- a/src/database/mongo/hash.js +++ b/src/database/mongo/hash.js @@ -23,7 +23,10 @@ module.exports = function(db, module) { }; module.getObjects = function(keys, callback) { - helpers.checkKeys(keys); + if (keys.length > helpers.KEY_LIMIT) { + var e = new Error('too many keys'); + winston.warn('[HASH - TOO_MANY_KEYS] ' + keys.length + ' ' + keys[0] + ' ' + keys[keys.length - 1] + '\n', e.stack); + } db.collection('objects').find({_key: {$in: keys}}, {_id: 0}).toArray(function(err, data) { if(err) { return callback(err); @@ -54,7 +57,11 @@ module.exports = function(db, module) { }; module.getObjectsFields = function(keys, fields, callback) { - helpers.checkKeys(keys); + if (keys.length > helpers.KEY_LIMIT) { + var e = new Error('too many keys'); + winston.warn('[HASH - TOO_MANY_KEYS] ' + keys.length + ' ' + keys[0] + ' ' + keys[keys.length - 1] + '\n', e.stack); + } + var _fields = { _id: 0, _key: 1 diff --git a/src/database/mongo/helpers.js b/src/database/mongo/helpers.js index 1eec59c3b8..d8e62fb3f1 100644 --- a/src/database/mongo/helpers.js +++ b/src/database/mongo/helpers.js @@ -9,7 +9,7 @@ helpers.toMap = function(data) { map[data[i]._key] = data[i]; } return map; -} +}; helpers.fieldToString = function(field) { if(field === null || field === undefined) { @@ -34,16 +34,6 @@ helpers.valueToString = function(value) { 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); - } -} +helpers.KEY_LIMIT = 100; module.exports = helpers; \ No newline at end of file diff --git a/src/database/mongo/sets.js b/src/database/mongo/sets.js index e12bc5caa0..7b0049068e 100644 --- a/src/database/mongo/sets.js +++ b/src/database/mongo/sets.js @@ -96,6 +96,10 @@ module.exports = function(db, module) { }; module.getSetsMembers = function(keys, callback) { + if (keys.length > helpers.KEY_LIMIT) { + var e = new Error('too many keys'); + winston.warn('[SET - TOO_MANY_KEYS] ' + keys.length + ' ' + keys[0] + ' ' + keys[keys.length - 1] + '\n', e.stack); + } db.collection('objects').find({_key: {$in: keys}}, {_key: 1, members: 1}).toArray(function(err, data) { if (err) { return callback(err);