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.