我想上传记录2500的excel文件。此过程需要大约5分钟的时间。我想将它优化到不到一分钟的最大值。 找到优化该代码的最佳方法。我正在使用Dbgeography进行位置存储。文件已上传并正确保存数据。一切正常,但我需要优化。
"path": "subscriptions/%sub_Id%/resourceGroups/%rg_Name%/providers/Microsoft.ClassicCompute/domainNames/%cloudService_Name%/servicecertificates/SHA1-%THUMBPRINT%",
"body": {
"thumbprintAlgorithm": "SHA1",
"thumbprint": "%THUMBPRINT%",
"data": "%base64encodedcert%",
"certificateFormat": "pfx",
"password": "password" << this is in plain text I believe
}
以下是上传文件的其他方法,并将其保存到数据库中。
public ActionResult Upload(HttpPostedFileBase FileUpload)
{
if (FileUpload.ContentLength > 0)
{
string fileName = Path.GetFileName(FileUpload.FileName);
string ext = fileName.Substring(fileName.LastIndexOf('.'));
Random r = new Random();
int ran = r.Next(1, 13);
string path = Path.Combine(Server.MapPath("~/App_Data/uploads"), DateTime.Now.Ticks + "_" + ran + ext);
try
{
FileUpload.SaveAs(path);
ProcessCSV(path);
ViewData["Feedback"] = "Upload Complete";
}
catch (Exception ex)
{
ViewData["Feedback"] = ex.Message;
}
}
return View("Upload", ViewData["Feedback"]);
}
答案 0 :(得分:2)
显而易见的起点是您对Geo Location服务的外部调用,看起来您正在为循环的每次迭代执行此操作。我不知道该服务,但有没有办法可以在内存中建立一个地址列表,然后用多个地址点击一次,然后返回并修改你需要更新的所有记录?
答案 1 :(得分:0)
对更新数据库的db.SaveChanges()的调用,每个行都会发生这种情况。
chrome.management.get(chrome.runtime.id, function(app_info){
if (app_info.installType == "development"){
endpoint = "https://api-dev.example.com";
}
else {
endpoint = "https://api-prod.example.com";
}
});
相反,只需在结尾处调用一次:
while (...)
{
...
db.StoreLocations.Add(store);
db.SaveChanges(); // Many database updates
}
这可以很好地加快你的代码。