如何優化以下代碼,該代碼目前需要2分鐘以上才能檢索並通過超過100K記錄的池中的800多條記錄進行循環,每個記錄返回6個字段(每個附加字段添加大約20秒):如何加快ColdFusion中.NET AD的數據檢索速度?
<cfset dllPath="C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.DirectoryServices.dll" />
<cfset LDAPPath="LDAP://" & arguments.searchPath />
<cfset theLookUp=CreateObject(".NET","System.DirectoryServices.DirectoryEntry", dllPath).init(LDAPPath) />
<cfset theSearch=CreateObject(".NET","System.DirectoryServices.DirectorySearcher", dllPath).init(theLookUp) />
<cfset theSearch.Set_Filter(arguments.theFilter) />
<cfset theObject = theSearch.FindAll() />
<cfloop index="row" from="#startRow#" to="#endRow#">
<cfset QueryAddRow(theQuery) />
<cfloop list="#columnList#" index="col">
<cfloop from="0" to="#theObject.Get_Item(row).Get_Properties().Get_Item(col).Get_Count()-1#" index="item">
<cftry>
<cfset theQuery[col][theQuery.recordCount]=ListAppend(theQuery[col][theQuery.recordCount],theObject.Get_Item(row).Get_Properties().Get_Item(col).Get_Item(item),"|") />
<cfcatch type="any">
</cfcatch>
</cftry>
</cfloop>
</cfloop>
</cfloop>
計數變量/緩存是沒有必要的 - CF將緩存從/爲CFLOOP值。 (儘管不是在cfscript中的循環語句) – 2008-09-17 18:01:55
我會這麼想,但我試圖證明一個觀點。 – x0n 2008-09-17 19:17:04