【发布时间】:2010-01-15 15:46:44
【问题描述】:
我在 3d 派对 ORM 框架中有一个 Page 类和一个 PageCollection 类。我可以根据参数(pageid、parentid、url 等)填充 PageCollection(SQL 查询)。但是我需要多次访问 ASP.NET MVC 网站(站点地图、身份验证)的数据,所以我选择加载所有页面 1 次并引用该(全局)集合。
GlobalClass.Pages //is PageCollection containing all pages
我现在已经创建了基于前面提到的参数(pageid、parentid、url 等)返回临时子集合或单个实体的函数。
GlobalClass.Pages.GetByPageId(id) //returns single page entity
GlobalClass.Pages.GetByParentId(parentid) //returns subcollection
但是网站变得很慢。
这里怎么走?
-
缓存子集合 (
GetByParent())? - 为集合创建内部哈希查找表?
- 还有什么...?
Namespace BLL
Public Class PageCollection
Inherits CustomCollectionBase
Public Sub New()
End Sub
Public Sub LoadByParent(ByVal PagParent As Integer)
If PagParent = 0 Then
Me.whereAdd('parent IS NULL')
Else
Me.whereAdd('parent = ' & PagParent.ToString())
End If
Me.Load(Me.data)
End Sub
Public Function GetBySiteMapNode(ByVal node As SiteMapNode) As BLL.Page
Return Me.GetByUrl(node.Url)
End Function
Public Function GetById(ByVal id As Integer) As BLL.Page
For Each p In Me
If p.PagAutoKey = id Then Return p
Next
Return Nothing
End Function
Public Function GetByUrl(ByVal url As String) As BLL.Page
For Each p In Me
If p.Url = url Then Return p
Next
Return Nothing
End Function
Public Function GetByParent(ByVal parent As Integer) As BLL.PageCollection
Dim pc As New PageCollection
For Each p In Me
If p.PagParent = parent Then pc.Add(p)
Next
Return pc
End Function
End Class
End Namespace
【问题讨论】:
-
是的,一些非常重要的信息没有给出:)
-
慢到底是什么? GetBy 方法是否比您预期的要慢?如果 GetBy 方法命中数据库而不是全局集合,它们会更快吗?
标签: .net asp.net-mvc vb.net collections performance