Question

I'm trying to pull back the last x number of list items in all non-hidden lists for a given web.

My original code would go through all lists and run the following code:

SPQuery query = new SPQuery();
query.Query = "<OrderBy><FieldRef Name =\"Modified\" Ascending=\"FALSE\"/></OrderBy>";
query.RowLimit = (uint)this.ItemsToDisplay;

switch(list.BaseType)
{
    case SPBaseType.DocumentLibrary:
        query.ViewAttributes = "Scope=\"Recursive\"";
        break;
    default:

        break;
}

SPListItemCollection listItems = list.GetItems(query);

effectively getting the last x items modified from each list and then I would put all of them into a List and sort, then taking the bottom x items.

This code was really slow (sometimes taking 20-30 seconds) so I decided to go down the route of using the ChangeLog.

Now i'm doing this code:

SPChangeQuery query = new SPChangeQuery(false, false);
query.Item = true;
query.Delete = false;
query.Add = true;
query.Update = true;
query.ChangeTokenStart = new SPChangeToken(SPChangeCollection.CollectionScope.Web, Web.ID, DateTime.Now.ToUniversalTime().AddDays(-14));
query.ChangeTokenEnd = new SPChangeToken(SPChangeCollection.CollectionScope.Web, Web.ID, DateTime.Now.ToUniversalTime());

SPChangeCollection changes = Web.GetChanges(query);

which works well in dev but has issues in prod. It turns out that in prod since we run MOSS and profiles are synced, I get 1000's of changes that are occuring in the user information list. So right now since the GetChanges method only pulls items in chunks of 1000, i have to use the lastchangetoken and call getchanges several times and then sort through 1000's of items just to get at the one's I want.

First question: Does anyone know how to exclude hidden lists or certain lists from a SPChangeQuery?

Second question: Is there a faster / better way of doing this? I thought about using Auditing to get the data since I have that turned on for all of our site collections but I haven't gone down that path yet.

Thanks.

Was it helpful?

Solution

SPListItems is not included in auditlog (per design due to performance issues) so you cant use auditing if you are looking for list items.

I would probably go for SPSiteDataQuery (as you mention yourself) which usually performs best for site-wide queries.

Another option would be the GetListItems web service which often i surprisingly fast...

A third option would be ProcessBatchData using the Display method, if it can be tweaked to deliver the data you need.

OTHER TIPS

Could you do it at a more granular level using SPList.GetChanges()? Obviously you'd have to do some merging of resultsets, but you'd probably be working with fewer overall change items. I guess a big factor would be how many lists you have, as this would be tied to how many merge operations your code would have to do..

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top