我有两个视图:Product/List,显示产品列表,Product/Details/{id},显示给定 ID 的产品详细信息。
用户每次点击 Product/List 视图中的产品项进入 Product/Details/{id} 视图时,大约需要 4 秒。我一直在研究什么需要这么长时间,并想让它更快一点。
因此,假设构造函数 ProductDetailsViewModel(int) 中的数据库调用导致延迟,我将我的操作方法 Details 更新如下。
[Route("Product/Details/{id}")]
public ActionResult Details(int? id) {
Stopwatch watch = new Stopwatch();
watch.Start();
var viewModel = new ProductDetailsViewModel(id);
watch.Stop();
int duration = watch.Elapsed.Milliseconds;
return View(viewModel);
}
但是,事实并非如此。duration
只有大约 500 到 600 毫秒。
我用谷歌搜索并做了尼克在http://nickberardi.com/timing-the-execution-time-of-your-mvc-actions/提供的类似操作
我一直得到大约 4 秒的 Product/Details/{id} 加载时间。请参阅下面的屏幕截图(chrome 开发工具)。
我有点不解。还有什么可能导致 action 方法的执行需要这么长时间?任何想法?谢谢。
更新了 Glimpse.Mvc5 时间线: