diff --git a/db.js b/db.js index 353d18f5..4dd88f70 100644 --- a/db.js +++ b/db.js @@ -1470,7 +1470,14 @@ module.exports.CreateDB = function (parent, func) { obj.StoreEvent = function (event, func) { obj.dbCounters.eventsSet++; sqlDbQuery('INSERT INTO events VALUES (NULL, $1, $2, $3, $4, $5, $6) RETURNING id', [event.time, ((typeof event.domain == 'string') ? event.domain : null), event.action, event.nodeid ? event.nodeid : null, event.userid ? event.userid : null, JSON.stringify(event)], function (err, docs) { - if ((err == null) && (docs[0].id)) { for (var i in event.ids) { if (event.ids[i] != '*') { sqlDbQuery('INSERT INTO eventids VALUES ($1, $2)', [docs[0].id, event.ids[i]]); } } } + if(func){ func(); } + if ((err == null) && (docs[0].id)) { + for (var i in event.ids) { + if (event.ids[i] != '*') { + sqlDbQuery('INSERT INTO eventids VALUES ($1, $2)', [docs[0].id, event.ids[i]], function(){ if(func){ func(); } }); + } + } + } }); }; obj.GetEvents = function (ids, domain, func) { @@ -3239,6 +3246,7 @@ module.exports.CreateDB = function (parent, func) { for (var i in docs) { pendingTransfer++; eventRecordsTransferCount++; + for (var b in docs[i].ids) { if (docs[i].ids[b] != '*') { pendingTransfer++; } } obj.StoreEvent(docs[i], function () { pendingTransfer--; }); } }