Skip to content

Instantly share code, notes, and snippets.

@lethern
Created March 30, 2021 23:17
Show Gist options
  • Save lethern/38c50f94da69a54d7b0b6bfc4cf0595e to your computer and use it in GitHub Desktop.
Save lethern/38c50f94da69a54d7b0b6bfc4cf0595e to your computer and use it in GitHub Desktop.
module.getItemNames = function (item_ids, cb) {
dbItems.find({ 'id': { $in: item_ids } }).toArray(function (err, docs) {
if (err) {
log.error("getContracts_items: Error for dbItems.find", { err });
cb(err);
return;
}
var fullquery = docs.map(d => d.id);
var newBulkSearch = diffArray(item_ids, fullquery);
console.log('getContracts_items docs ' + docs.length + ', newBulkSearch (capped) ' + newBulkSearch.length);
if (newBulkSearch.length == 0) {
cb(null, docs);
return;
}
try {
UniverseApi.postUniverseNames(newBulkSearch, {}, callback);
} catch (e) {
console.error('postUniverseNames', e);
cb(e);
}
function callback(error, data, response) {
if (error) {
console.error('getItemNames', error);
cb(error);
return;
}
dbItems.insertMany(data, function (err, result) {
if (err) {
log.error("insertMany: Error for db.insertMany", { err });
cb(err);
return;
}
let all_data = docs.concat(data);
cb(null, all_data);
});
};
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment