我正在編寫一些C#(.NET)與Umbraco 4.7一起使用以將文章導入到博客中。簡而言之,這種算法被設計用於遍歷每一篇現有文章,並檢查它是否與我們試圖從XML中引入的新文章具有相同的ID。該算法工作正常,但我不禁覺得有四個foreach循環對我所做的事情來說效率非常低。檢查樹形結構中的每個節點,使用Umbraco(提高效率)
foreach (Document yearNode in node.Children) //News > Years
{
foreach (Document monthNode in yearNode.Children) //Years > Months
{
foreach (Document dayNode in monthNode.Children) //Months > Days
{
foreach (Document newsItem in dayNode.Children) //Days > Articles
{
// If there isn't an ID match, go ahead and create a new article node.
}
這是沒有它的主要功能的基本算法,只是foreach循環。這比簡單地循環日曆日期要複雜一些,因爲它更像是包含特定節點的文件夾結構。任何人都可以建議一種簡化這一點的方法嗎?
Umbraco特定類型上方的'Document'類型? – reuben 2012-07-09 08:56:27
是的,是的。作爲BusinessLogic的一部分,[鏈接](http://our.umbraco.org/wiki/reference/api-cheatsheet/creating-a-document) – edparry 2012-07-09 09:01:20
您可以建立文檔文件夾結構的緩存,並執行在緩存中快速查找? – reuben 2012-07-09 09:12:54