0

我有一个视图模型的强类型视图,并且自从我今天早上进行了一些代码更新以来,它的运行速度非常慢。我安装了 Glimpse MVC 以查看是否可以更好地了解可能发生的情况。Glimpse 适用于除 ViewModel 页面之外的每个页面 - 选项卡消失但不输出任何信息。

我的 Glimpse 日志文件说:

2012-06-22 13:50:29.5831|INFO|Glimpse.Core.Module|BeginRequest handling complete for requestId 64d0e726-a756-4c1a-a9c4-629231948aa2 (/SurveyResponse/Results)|
2012-06-22 13:50:29.5851|WARN|Glimpse.Mvc3.Plugin.Execution|get_Binders method of System.Web.Mvc.ControllerActionInvoker type is not proxyable.|
2012-06-22 13:50:29.5851|WARN|Glimpse.Mvc3.Plugin.Execution|set_Binders method of System.Web.Mvc.ControllerActionInvoker type is not proxyable.|
2012-06-22 13:50:29.5851|WARN|Glimpse.Mvc3.Plugin.Execution|GetType method of System.Web.Mvc.ControllerActionInvoker type is not proxyable.|
2012-06-22 13:50:29.6101|WARN|Glimpse.Mvc3.Plugin.Execution|MemberwiseClone method of System.Web.Mvc.ControllerActionInvoker type is not proxyable.|
2012-06-22 13:50:30.5192|INFO|Glimpse.Core.Module|PostRequestHandlerExecute handling complete for requestId 64d0e726-a756-4c1a-a9c4-629231948aa2 (/SurveyResponse/Results)|
2012-06-22 13:50:30.5212|INFO|Glimpse.Core.Module|PostReleaseRequestState handling complete for requestId 64d0e726-a756-4c1a-a9c4-629231948aa2 (/SurveyResponse/Results)|
2012-06-22 13:50:30.5462|WARN|Glimpse.Core.Plumbing.GlimpseSerializer|Serializer error|System.ObjectDisposedException--The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.--   at System.Data.Objects.ObjectContext.EnsureConnection()
   at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
   at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
   at System.Data.Entity.Internal.Linq.InternalQuery`1.GetEnumerator()
   at System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.Generic.IEnumerable<TResult>.GetEnumerator()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Newtonsoft.Json.Serialization.JsonArrayContract.CreateWrapper(Object list)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContract collectionValueContract)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.WriteMemberInfoProperty(JsonWriter writer, Object memberValue, JsonProperty property, JsonContract contract)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContract collectionValueContract)
2012-06-22 13:50:30.5602|WARN|Glimpse.Core.Plumbing.GlimpseSerializer|Serializer error|System.ObjectDisposedException--The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.--   at System.Data.Objects.ObjectContext.EnsureConnection()
   at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
   at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
   at System.Data.Entity.Internal.Linq.InternalQuery`1.GetEnumerator()
   at System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.Generic.IEnumerable<TResult>.GetEnumerator()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Newtonsoft.Json.Serialization.JsonArrayContract.CreateWrapper(Object list)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContract collectionValueContract)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.WriteMemberInfoProperty(JsonWriter writer, Object memberValue, JsonProperty property, JsonContract contract)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContract collectionValueContract)
2012-06-22 13:50:30.5602|INFO|Glimpse.Core.Module|Glimpse JSON payload created for requestId 64d0e726-a756-4c1a-a9c4-629231948aa2 (/SurveyResponse/Results)|
2012-06-22 13:50:30.5702|INFO|Glimpse.Core.Module|Glimpse output generated for requestId 64d0e726-a756-4c1a-a9c4-629231948aa2 (/SurveyResponse/Results)|
2012-06-22 13:50:30.5702|INFO|Glimpse.Core.Module|RequestId 64d0e726-a756-4c1a-a9c4-629231948aa2 (/SurveyResponse/Results) persisted|
2012-06-22 13:50:30.5702|INFO|Glimpse.Core.Module|EndRequest handling complete for requestId 64d0e726-a756-4c1a-a9c4-629231948aa2 (/SurveyResponse/Results)|
2012-06-22 13:50:30.6272|INFO|Glimpse.Core.Module|BeginRequest handling complete for requestId 44be221e-a7e2-4ac7-bd4c-29ae2b9ad12f (/Glimpse.axd)|
2012-06-22 13:50:30.6422|WARN|Glimpse.Core.Validator.GlimpseRequestValidator|Glimpse.Core.Validator.ContentTypeValidator invalided request (it will now be ignored) with id 44be221e-a7e2-4ac7-bd4c-29ae2b9ad12f (/Glimpse.axd)|
2012-06-22 13:50:30.6482|WARN|Glimpse.Core.Validator.GlimpseRequestValidator|Glimpse.Core.Validator.ContentTypeValidator invalided request (it will now be ignored) with id 44be221e-a7e2-4ac7-bd4c-29ae2b9ad12f (/Glimpse.axd)|
2012-06-22 13:50:30.6482|WARN|Glimpse.Core.Validator.GlimpseRequestValidator|Glimpse.Core.Validator.ContentTypeValidator invalided request (it will now be ignored) with id 44be221e-a7e2-4ac7-bd4c-29ae2b9ad12f (/Glimpse.axd)|
2012-06-22 13:50:30.6642|WARN|Glimpse.Core.Validator.GlimpseRequestValidator|Glimpse.Core.Validator.ContentTypeValidator invalided request (it will now be ignored) with id 44be221e-a7e2-4ac7-bd4c-29ae2b9ad12f (/Glimpse.axd)|

导致性能不佳的代码是在我的 group by 查询中添加这些 Select 语句:

 var data = from SurveyResponseModel in db.SurveyResponseModels
                       group SurveyResponseModel by SurveyResponseModel.MemberId into resultCount
                       select new ResultsViewModel()
                       {
                           MemberId = resultCount.Key,
                           PatientFollowUpResult = db.SurveyResponseModels.Count(r => r.PatientFollowUp),
                           ChangeCodingPracticeResult = db.SurveyResponseModels.Count(r => r.ChangeCodingPractice),

                           ChangesOthersResult = resultCount.Select(r => r.ChangesOthers),

                           YesBarriersOthersResult = resultCount.Select(r => r.YesBarriersOthers),

                           AddressBarriersOthersResult = resultCount.Select(r => r.AddressBarriersOthers),
                           TotalResponsesResult = db.SurveyResponseModels.Count(),
                       };
4

1 回答 1

0

我想说这里发生的事情是 Glimpse 正在触发模型中属性的延迟加载。不幸的是,Glimpae 目前不支持这种情况。要测试是否是这种情况,请尝试禁用视图选项卡,看看您是否有同样的问题。

于 2012-06-23T13:02:23.870 回答