由于三条in查询并没有顺序要求,我们这里用Promise.all()做parallel query而不是sequential query是不是更好些
const arts = []
for (let key in artInfoObj) {
const ids = artInfoObj[key]
if (ids.length === 0) {
continue
}
key = parseInt(key)
arts.push(await Art._getListByType(ids, key))
}
return flatten(arts)
代码如下
const arts = [];
for (let key in artInfoObj) {
const ids = artInfoObj[key];
if (ids.length !== 0) {
key = parseInt(key);
arts.push(Art._getListByType(ids, key));
}
}
const result = await Promise.all(arts);
return flatten(result);