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) {
this.getBucketAttributes(bucketName, log, (err, bucket) => {
if (err) {
log.error(
'getBucketAttributes: error getting bucket attributes',
{ error: err.message });
return cb(err);
}
this.getObject(bucketName, objName, params, log, (err, obj) => {
if (err) {
if (err === errors.NoSuchKey) {
return cb(null,
{ bucket:
BucketInfo.fromObj(bucket).serialize(),
});
return async.parallel({
bucket: callback => {
this.getBucketAttributes(bucketName, log, (err, bucket) => {
if (err) {
log.error(
'getBucketAndObject: error getting bucket attrs',
{ error: err.message });
return callback(err);
}
log.error('getObject: error getting object',
{ error: err.message });
return cb(err);
}
return cb(null, {
bucket: BucketInfo.fromObj(bucket).serialize(),
obj: JSON.stringify(obj),
return callback(null, bucket);
});
},
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;
});
}