在專案中我們把大量的資料由 Notes 轉換到 SharePoint Portal Server 2003 上頭來,開發了 Export 及 Import 的程式來進行,在 Import 的時候發現到 Insert 的速度會隨著塞入的資料量增多而變得越來越慢,後來發現 SPS2003 的 List 有 2000 筆的建議限制,限制歸限制它僅僅只是一個建議值,事實上你在它上頭放幾萬筆 ListItem 也不會有問題,但就是『慢!!!』。

在載入一萬多筆舊資料之後,每一筆的新增大概會占掉 14 秒的時間,這使得使用 SPList.Items.Add() (< -- 就是慢在這) 指令所寫的資料寫入程式在 Import 兩萬筆資料時要花費大約兩天的時間才可以做完所有的工作。不僅僅是這樣,資料進入 SPS2003 後我們會有一些 Application 會使用這上面的資料,並對 ListItem Collection 進行新增或刪除的動作,這表示所有的程式日後跑起來也會有相同的問題。 微軟的 Product Support 給的答案並沒有辦法令人滿意,所以我們另外挖了 SDK 中個另一個 API (SPWeb.ProcessBatchData),使用這個方法可以不用操作到 SPList.Items 這個 Collection,大大的加速了新增及刪除的動作,搜尋了一下 Google 只有兩篇文章寫相關的內容,也是使用這個方法解決的,如果你的 List 在設計上就是會一直長大的,而且有潛力會超過兩千個 ListItem,那麼應該要改用這個 Method 來進行新增跟刪除的動作,不要用 SPList.Items 來操作,不過據微軟說,這樣寫出的程式不在支援之列就是了,反正就是寫了一個不給用的 API ?? 這一段在 SPS2003 的 SDK 文件中也可以找得到,它真的可以省下很多的時間!! 如果可以,我個人建議大家都改用這種方法。 Keyword: SPS2003, Sharepoint, Large List, Bulk insert, SPList, SPListItem, Slow, Performance. ProcessBatchData Method The ProcessBatchData method of the SPWeb class processes the specified batch string of commands for sending multiple requests to the server per transaction. [Visual Basic .NET]Public Function ProcessBatchData( _ ByVal strBatchData As String _ ) As String [C#]public string ProcessBatchData( string strBatchData ); Parameters strBatchData A string in Collaborative Application Markup Language (CAML) that contains the batch string of commands, which consists of a Batch element and any number of Method subelements that each specify a Windows SharePoint Services RPC method. Return Value A string that contains the results. Example The following code example uses the ProcessBatchData method to add two items to the Announcements list of a specified site in the current site collection. [Visual Basic .NET]Dim siteCollection As SPSite = SPControl.GetContextSite(Context) Dim site As SPWeb = siteCollection.AllWebs("TestWeb1") Dim list As SPList = site.Lists("Announcements") Dim guid As System.Guid = list.ID Dim myGuid As String = guid.ToString() Dim strPost As String = "” _
& “” _
& myGuid & “
New” _
& “Save” _
& “” _
& “New Manager
” _
& “Congratulations to Mary for her promotion!
” _
& “” _
& “2003-09-14T00:00:00Z
” _
& “” & myGuid & “New” _
& “Save” _
& “” _
& “New Technical Consultant
” _
& “” _
& “Welcome to the team, John!
” _
& “” _
& “2003-10-15T00:00:00Z

Dim processBatch As String = site.ProcessBatchData(strPost)
[C#]SPSite siteCollection = SPControl.GetContextSite(Context);
SPWeb site = siteCollection.AllWebs[“TestWeb1”];

SPList list = site.Lists[“Announcements”];

System.Guid guid = list.ID;

string myGuid = guid.ToString();

string strPost = “< ?xml version=\"1.0\" encoding=\"UTF-8\"?>” +
” +
” + myGuid + “” +
New” +
Save” +
” +
“New Manager
” +
” +
“Congratulations to Mary for her promotion!
” +
” +
“2003-09-14T00:00:00Z
” +
” +
” +
” + myGuid + “” +
New” +
Save” +
” +
“New Technical Consultant
” +
” +
“Welcome to the team, John!
” +
” +
“2003-10-15T00:00:00Z
” +
” +
“;

string processBatch = site.ProcessBatchData(strPost);
This example requires using directives (Imports in Visual Basic) for both the Microsoft.SharePoint and Microsoft.SharePoint.WebControls namespaces.

最後修改日期: 2006-10-31

作者

留言

撰寫回覆或留言

發佈留言必須填寫的電子郵件地址不會公開。