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 Feb 18, 2015
1 parent 57c8e99 commit a67e532
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

1 comment on commit a67e532

@bewest
Copy link

@bewest bewest commented on a67e532 Feb 18, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super nice job on this. Excellent, excellent work.

Please sign in to comment.