Friday, May 1, 2009

DataSource CAML Keywords

So recently I needed to display the newest item added to a Very Large List via a dataform web part. The performance on SPQuery is pretty good as long as you return less than 2000 rows from your query. This means that you can't just return all of the list items from the datasource and then sort for the newest one. Instead I used some CAML keywords to help out. My DataSource query filtered on:

<Eq><FieldRef Name="Author" /><Value Type="Integer"><UserID /></Value></Eq>

and

<Eq><FieldRef Name="Created"/><Value Type="DateTime"><Today/></Value></Eq>

These two CAML rendering elements (for the current date, and current users ID). Helped the query return a very small number of rows, which could then be sorted by created date to show the newest.

No comments: