Reputation: 93
We have a MVC 4 Web application. I used miniprofiler to check how long it is taking and it shows that the render of a view with three partial views is taking a very long time. I tried moving the information in the partial views directly onto the page and that didn't make a difference in the times at all. What should I do to reduce the render time? Any tips on where I should start looking? As you can see, the render is taking 48 seconds.
**| duration | from start(ms)**
|http://localhost:61380/CaseContacts | 653.7 | +0.0
|Controller: CaseController.Contacts | 11.9 | +641.1
| Contacts view - not an ajax request | 0.3 | +651.7
| populating view model | 0.0 | +652.1
| getting list of contacts | 374.4 | +652.1
| Find: Contacts | 499.8 | +1033.6
| Render: Contacts | 48400.8 | +1535.2
**| client event |duration(ms)| from start(ms)**
|Request start | | +2.0
|Response | 1.0 | +52245.0
|Dom loading | | +52247.0
|scripts | 390.0 | +52315.0
|Dom Content Loaded Event| 29.0 | +52707.0
|Dom Interactive | | + 52707.0
|Load Event | | + 52760.0
|Dom Complete | | + 52760.0
Update:
public IQueryable<T> FindQueryable(Expression<Func<T, bool>> predicate, Func<T, Object> orderBy)
{
return this.db.GetAll<T>().Where(predicate).OrderBy(orderBy).AsQueryable<T>();
}
public class ContactRepository : Repository<USRContact>, IContactRepository<USRContact>
{
public IList<ContactNameViewModel> GetAll(int fieldOfficeID, string searchText = "")
{
if (searchText.Length > 0)
return Mapper.Map<IList<USRContact>, IList<ContactNameViewModel>>(this.FindQueryable(x => (x.FieldOfficeID == fieldOfficeID) &&
(x.FormalName.Contains(searchText) || x.PreferredName.Contains(searchText) || x.Alias.Contains(searchText) || x.Pseudonym.Contains(searchText)), x => (x.STMGender.Gender)).ToList());
else
return Mapper.Map<IList<USRContact>, IList<ContactNameViewModel>>(this.FindQueryable(x => (x.FieldOfficeID == fieldOfficeID)).ToList());
}
Then my controller is loading the results onto a viewmodel and then:
@Html.Partial("~/Views/Shared/Contacts/ContactNameList.cshtml", Model.Contacts)
The partial view contains the following code:
@model IList<Casenator.Web.Models.Contact.ContactNameViewModel>
<ul id="NameList" style="margin-left:0">
@foreach (var item in Model)
{
@*<li>@Html.RouteLink(@item.FullName, "Contacts", new { id = item.ContactID })</li>*@
<li>@Ajax.RouteLink(item.FullName, "Contacts", new { id = item.ContactID }, new AjaxOptions { UpdateTargetId = "BasicInfo", OnSuccess="InitializeComboBoxes", OnBegin="LoadContact(" + item.ContactID + ")" }) </li>
}
</ul>
Any help will be appreciated! Thanks, Safris
Upvotes: 3
Views: 3460
Reputation: 8199
What you are returning from query is important. If you are returning IEnumerable
It would be better to reurn IQueryable
. You may see this question it may help you in your situation
I don't think automapper
like tools are designed to map many recoreds. you may try to map the object manually
Upvotes: 2