优化并行处理和代码可读性

格式化了 `data.Where` 的条件部分以提高可读性。
将并行度从 1 提升到 8 以提高性能。
This commit is contained in:
lihanbo 2024-11-08 10:21:10 +08:00
parent 83449ea2dd
commit a10a4371ba
1 changed files with 16 additions and 10 deletions

View File

@ -196,20 +196,26 @@ public partial class MainViewModel : INotifyPropertyChanged
var reportDatas = new ConcurrentBag<ReportModel>();
//foreach (var entry in data)
data.Where(it => it.OrigOcc == "OccWire" && !(it?.Properties["WireName"]?.GetDisplayValue()?.StartsWith("导线") ?? false)).AsParallel().WithDegreeOfParallelism(1).ForAll(entry =>
{
var obj = new ReportModel();
foreach (var column in columns)
data.Where(it =>
it.OrigOcc == "OccWire"
&& !(it?.Properties["WireName"]?.GetDisplayValue()?.StartsWith("导线") ?? false)
)
.AsParallel()
.WithDegreeOfParallelism(8)
.ForAll(entry =>
{
if (!entry.Properties.ContainsKey(column.ColumnID)) continue;
var value = entry.Properties[column.ColumnID].GetDisplayValue();
var obj = new ReportModel();
foreach (var column in columns)
{
if (!entry.Properties.ContainsKey(column.ColumnID)) continue;
var value = entry.Properties[column.ColumnID].GetDisplayValue();
var property = typeof(ReportModel).GetProperty(column.ID);
property?.SetValue(obj, value ?? "");
var property = typeof(ReportModel).GetProperty(column.ID);
property?.SetValue(obj, value ?? "");
}
reportDatas.Add(obj);
}
reportDatas.Add(obj);
}
);
return Task.FromResult(reportDatas.ToList());
}