Compare commits

...

1 Commits

Author SHA1 Message Date
vrancurel 870f0721bc improvement: parallelize get bucket and get object 2020-02-06 11:18:50 -08:00
1 changed files with 37 additions and 22 deletions

View File

@ -250,31 +250,46 @@ class MongoClientInterface {
} }
getBucketAndObject(bucketName, objName, params, log, cb) { getBucketAndObject(bucketName, objName, params, log, cb) {
this.getBucketAttributes(bucketName, log, (err, bucket) => { return async.parallel({
if (err) { bucket: callback => {
log.error( this.getBucketAttributes(bucketName, log, (err, bucket) => {
'getBucketAttributes: error getting bucket attributes', if (err) {
{ error: err.message }); log.error(
return cb(err); 'getBucketAndObject: error getting bucket attrs',
} { error: err.message });
this.getObject(bucketName, objName, params, log, (err, obj) => { return callback(err);
if (err) {
if (err === errors.NoSuchKey) {
return cb(null,
{ bucket:
BucketInfo.fromObj(bucket).serialize(),
});
} }
log.error('getObject: error getting object', return callback(null, bucket);
{ error: err.message });
return cb(err);
}
return cb(null, {
bucket: BucketInfo.fromObj(bucket).serialize(),
obj: JSON.stringify(obj),
}); });
},
obj: callback => {
this.getObject(bucketName, objName, params, log, (err, obj) => {
if (err) {
if (err === errors.NoSuchKey) {
return callback(null, null);
}
log.error('getBucketAndObject: error getting object',
{ error: err.message });
return callback(err);
}
return callback(null, obj);
});
},
}, (err, results) => {
if (err) {
return cb(errors.InternalError);
}
const { bucket, obj } = results;
if (!obj) {
return cb(null,
{ bucket:
BucketInfo.fromObj(bucket).serialize(),
});
}
return cb(null, {
bucket: BucketInfo.fromObj(bucket).serialize(),
obj: JSON.stringify(obj),
}); });
return undefined;
}); });
} }