Skip to content

Commit

Permalink
create all docs before calling back
Browse files Browse the repository at this point in the history
  • Loading branch information
dduugg committed Mar 1, 2015
1 parent d616b6c commit f494399
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions lib/entries.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,22 @@ function storage(name, storage, pushover) {

// store new documents using the storage mechanism
function create (docs, fn) {
with_collection(function(err, collection) {
if (err) { fn(err); return; }
// potentially a batch insert
var firstErr = null,
totalCreated = 0;

docs.forEach(function(doc) {
collection.update(doc, doc, {upsert: true}, function (err, created) {
firstErr = firstErr || err;
totalCreated += created;
});
sendPushover(doc);
with_collection(function(err, collection) {
if (err) { fn(err); return; }
// potentially a batch insert
var firstErr = null,
totalCreated = 0;

docs.forEach(function(doc) {
collection.update(doc, doc, {upsert: true}, function (err, created) {
firstErr = firstErr || err;
if (++totalCreated >= docs.length) {
fn(firstErr, totalCreated, docs);
}
});
fn(firstErr, totalCreated, docs);
sendPushover(doc);
});
});
}

//currently the Android upload will send the last MBG over and over, make sure we get a single notification
Expand Down

0 comments on commit f494399

Please sign in to comment.