A general architecture question in Sitecore 6...
Let’s say we have a situation where we have 10,000 items implementing a “Press Release” template. These items are stored in Sitecore at */sitecore/content/home/press/**. On our homepage, we’d like to display some information concerning the 3 most recent press releases.
We’re looking to construct something equivalent to SQL’s:
SELECT TOP 3 * FROM PressReleases ORDER BY ReleaseDate
Reading through the Sitecore query documentation, it sounds like the majority of this query must be handled in our C# application. Something like:
public Item[] GetRecentPressReleases()
{
string query = "/sitecore/content/home/press/*";
Item[] items = Sitecore.Context.Database.SelectItems(query);
Array.Sort(items, new PressReleaseDateComparer());
return items.Take(3).ToArray();
}
It would seem that loading 10,000 Sitecore items from the database into memory and then sorting them every time our homepage is hit would be unacceptable from a performance perspective.
Is there a more efficient way to express this query? Or should I be focused on output caching or precalculating?