0

我仍然有一个问题,但在人们的帮助下,我越来越接近了。

我使用 EF Profiler,我看到当我加载仪表板控制器时,它正在运行许多查询,这些查询“基本上”从数据库中拉回相同的数据。这是我的控制器示例:

Public Class DashboardController
    Inherits BaseController

    Private ticketRepo As MaintenanceTicketsRepository

    Public Sub New()
        Me.ticketRepo = New MaintenanceTicketsRepository(New TicketContext)
    End Sub

    Function Chart_OpenItemsByPM() As ActionResult
        Dim tickets As IList(Of MaintenanceTicket) = ticketRepo.GetAll().Include(Function(p) p.Priority).Include(Function(s) s.Status).OrderBy(Function(o) o.PriorityId).ToArray()

        Dim queue As PieChartViewModel() = Mapper.Map(Of MaintenanceTicket(), PieChartViewModel())(tickets)

        Dim ticketCounts = From t In queue _
                           Where t.StatusName = "Open" And _
                           t.PriorityName <> "Not Ready" _
                           Group t By t.PriorityName Into Count() _
                           Select New With {
                               .PriorityName = PriorityName,
                               .Id = Count,
                               .Explosion = If(.PriorityName = "Critical", "True", "False")
                           }

        Return Json(ticketCounts)
    End Function

    Function Grid_OpenItemsByPriority(<DataSourceRequest()> request As DataSourceRequest) As ActionResult
        Dim tickets As IList(Of MaintenanceTicket) = ticketRepo.GetAll().Include(Function(p) p.Priority).Include(Function(s) s.Status).ToArray()

        Dim queue As GridViewModel() = Mapper.Map(Of MaintenanceTicket(), GridViewModel())(tickets)

        Dim ticketCounts = From t In queue _
                           Where _
                           t.StatusId = 1 And _
                           t.CreateDate.Year = Convert.ToDateTime(DateTime.Now).Year _
                           Group t By _
                           Column1 = CType(t.CreateDate.Month, Integer), _
                           Column2 = CType(t.CreateDate.ToString("MMMM"), String) _
                           Into g = Group _
                           Order By Column1 _
                           Select New With {
                               .Id = Column1,
                               .Month = Column2,
                               .Critical = g.Count(Function(t) t.PriorityId = 1),
                               .High = g.Count(Function(t) t.PriorityId = 2),
                               .Normal = g.Count(Function(t) t.PriorityId = 3),
                               .Low = g.Count(Function(t) t.PriorityId = 4),
                               .NotReady = g.Count(Function(t) t.PriorityId = 5),
                               .Total = g.Count(Function(t) t.Id <> Nothing)
                           }

        Return Json(ticketCounts.ToDataSourceResult(request))
    End Function

    Protected Overrides Sub Dispose(disposing As Boolean)
        ticketRepo.Dispose()
        MyBase.Dispose(disposing)
    End Sub
End Class

你会看到有一些函数(通过 ajax 调用到 Kendo Controls 中)但是每个函数都会填充存储库,然后将数据映射到我的视图模型中,然后我需要进行排序并执行真正的过程以获得最终输出. 我在每个函数中都这样做,并且我的页面上的加载时间很长,并且它正在刺激服务器。

关于如何通过一个查询加载 repo 的任何想法?

4

1 回答 1

0

我最终使用存储过程来限制返回到我的存储库的数据,从而加快数据访问速度。

于 2013-01-02T20:50:17.153 回答