Re: clear a large list faster, write a large list faster

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Aaron,

No need to touch the database in this case and no point threading, SQL
IO's are your bottleneck here.
For large inserts and deletes avoid the Object Model at all costs as it
refreshes its collection for every operation, your SQL IO's will be
through the roof.

Once you have the list of item ID's use straight CAML to do the
deletes, its an order of magnitude faster.
Assuming you have a SPWeb object this is the fastest way to delete
records although you can actually batch the deletes into a larger
string if you really feel inclined to.

SPList list=web.Lists["Announcements"];
SPListItemCollection cl= list.Items;

ArrayList itemids=new ArrayList();
foreach (SPListItem item in cl) itemids.Add(item.ID);

// Setup the base CAML string
string xmlcaml="<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<Batch>" +
"<Method>" +
"<SetList Scope=\"Request\">" + list.ID +"</SetList>" +
"<SetVar Name=\"ID\">{0}</SetVar>" +
"<SetVar Name=\"Cmd\">Delete</SetVar>" +
"</Method>" +
"</Batch>";

// Avoid Object Model use CAML passthrough
foreach (object itemid in itemids)
web.ProcessBatchData(string.Format(xmlcaml,(int)itemid));



BTW there's a .Development group for coding questions.
Check my reply on this thread for the CAML insert syntax
http://groups.google.com/group/microsoft.public.sharepoint.windowsservices.development/browse_frm/thread/2f953b21e79f76be/a5cea4f9d6f2034d?lnk=st&q=flexnetconsult+method&rnum=2#a5cea4f9d6f2034d

Colin Byrne
Flexnet Consultants

Free Picture Library Flash Slideshow WebPart
http://www.flexnetconsult.co.uk/WebParts/WebParts.htm

.



Relevant Pages