此代码的全部目的是将转储到CommRef_中的数据排列到" ResObj"的所需结构中。
问题是,一些" CommRef"数组中可以包含多达35,000个元素。这会导致操作在当前硬件上占用13秒的字。
因此,我要仔细检查如何提高效率。
任何建议??
P.S。处理大数字的唯一地方是// Build Row Array Loop
结构前
{ "TableName": [
{ "PartNumber": "Widget00001", "PartName": WidgetName },
{ "PartNumber": "Widget00002", "PartName": WidgetName },
ect.....,
{ "PartNumber": "Widget35001", "PartName": WidgetName }
]
结构需求后
{
"DataSources": [
{
"Id": "PartNumbers",
"DeletedRows": [],
"NewRows": [],
"Rows": [
[
"00001",
"WidgetName"
],
[
"00002",
"WidgetName"
],
[
"35001",
"WidgetName"
]
]
}
]
}
代码
RefDataTables.forEach(function(t,ti){
try{
if(CommRef_[t]){
if (CommRef_[t].hasOwnProperty("error")){
response.statusCode = 500;
responseBody = responseBody + "\n" + JSON.stringify(CommRef_[t].error);
}else{
response.statusCode = 200;
//Build Row Array
rowsObj = {"Rows":[]};
CommRef_[t].forEach(function(d,di){
rowsObj.Rows.push(_.values(CommRef_[t][di]));
});
//Build NewRows Array
//Build Deleted Rows Array
//Append DataSources Array
ResObj.DataSources.push({"Id": t, "Rows":rowsObj.Rows, "NewRows":[], "DeletedRows":[]});
}
}else{
ResObj.DataSources.push({"Id": t, "Rows":[], "NewRows":[], "DeletedRows":[]});
}
}
catch(err){
responseBody = responseBody + "\n" + JSON.stringify("Ref Data Object Build Error " + err);
}
});