I have a view that is strongly typed to a view model, and has started running really slowly since I made some code update this morning. I installed Glimpse MVC to see if I could get a better idea about what might be happening. Glimpse works on every page except the ViewModel page - the tab disappears without outputting any information.
My Glimpse log file says:
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)|
The code that caused the poor performance was adding these Select statements inside of my group by query:
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(),
};