I'm looking for the best performing means of querying for site data within a site collection. I need to query for all of the lists in either a particular SPWeb, or a set of SPWeb's, that contain a specific content type. The project I'm working on currently uses code like the following:
private void EnumerateChildWebs(SPWeb web, bool firstTime) { if (!firstTime) { EnumerateListCol(web.Lists); } foreach (SPWeb child in web.Webs) { EnumerateChildWebs(child, false); child.Dispose(); } } private void EnumerateListCol(SPListCollection spListCol) { SPList list; SPContentTypeId ctid; for (int i = 0; i < spListCol.Count; i++) { list = spListCol[i]; if (list.ContentTypesEnabled && list.BaseType == SPBaseType.DocumentLibrary) { foreach (SPContentType ct in list.ContentTypes) { // [Omitted] - Code to check if the list contains a particular content type if (ct.ID matches the one we're looking for) { // Do something with the list break; } } } } }
My question is, would it generally be better to use an SPSiteDataQuery to do this? It seems like it would yield much cleaner code, but what about performance? Is there any conventional wisdom around when to use SPSiteDataQuery? I've read some information on it on the web, but nothing that addresses my particular scenario.