From 10be06c619f801e34129c0da27da135be8f2c1a2 Mon Sep 17 00:00:00 2001 From: Zaid Abdulla Date: Mon, 21 Apr 2014 20:20:27 +0300 Subject: [PATCH] Avoid invoking mapReduce in complieAliases when database has not been created yet. Fixes #4. --- lib/parameters.coffee | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/parameters.coffee b/lib/parameters.coffee index 2ae0030..4aa9e12 100644 --- a/lib/parameters.coffee +++ b/lib/parameters.coffee @@ -85,10 +85,11 @@ createParameterAttributeFinder = (attributeName) -> splitIds = (batches, callback) -> - ids = [{}] - return callback(ids) if batches == 1 db.devicesCollection.count((err, count) -> - return callback(ids) if count <= 1000 + throw err if err + return callback(null) if count == 0 + ids = [{}] + return callback(ids) if count <= 1000 or batches == 1 batchSize = Math.floor(count / batches) for i in [1 ... batches] ids[i] = {} @@ -158,6 +159,9 @@ compileAliases = (callback) -> counter = 0 splitIds(4, (batches) -> + if not batches? + return callback(null, aliases, config.ALIASES_CACHE) + for batch in batches options = { out : {inline : 1}