From 392e37ab05aed0f07d369282a92d6d676c5f7ce7 Mon Sep 17 00:00:00 2001 From: baldo Date: Sun, 26 Jun 2016 19:27:09 +0200 Subject: [PATCH] Fix: "SQLITE_ERROR: too many SQL variables" when loading nodes --- server/services/monitoringService.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/server/services/monitoringService.js b/server/services/monitoringService.js index 63e48f9..d402d45 100644 --- a/server/services/monitoringService.js +++ b/server/services/monitoringService.js @@ -20,6 +20,7 @@ angular.module('ffffng') Constraints, Resources ) { + var MONITORING_STATE_MACS_CHUNK_SIZE = 100; var MONITORING_MAILS_DB_BATCH_SIZE = 50; var MONITORING_OFFLINE_MAILS_SCHEDULE = { 1: { amount: 3, unit: 'hours' }, @@ -411,22 +412,28 @@ angular.module('ffffng') return callback(null, {}); } - var inCondition = DatabaseUtil.inCondition('mac', macs); + async.map( + _.chunk(macs, MONITORING_STATE_MACS_CHUNK_SIZE), + function (subMacs, subCallback) { + var inCondition = DatabaseUtil.inCondition('mac', subMacs); - Database.all( - 'SELECT * FROM node_state WHERE ' + inCondition.query, - _.concat([], inCondition.params), - function (err, rows) { + Database.all( + 'SELECT * FROM node_state WHERE ' + inCondition.query, + _.concat([], inCondition.params), + subCallback + ); + }, + function (err, rowsArrays) { if (err) { return callback(err); } var nodeStateByMac = {}; - _.each(rows, function (row) { + _.each(_.flatten(rowsArrays), function (row) { nodeStateByMac[row.mac] = row; }); - callback(null, nodeStateByMac); + return callback(null, nodeStateByMac); } ); },