I have a site with about 40K documents. The website has a homepage which shows the most recently added content.
To show the latest content, I sort by a "publication date" property. Obviously, you want to do this in Examine, to avoid instantiating all 40,000 nodes. However, it appears to be impossible to sort by a custom property with Examine.
Here is the stored procedure version, which is unfortunately still quite slow:
CREATE PROCEDURE ArticlesGetLatest
@PageSize int = 100,
@PageNumber int = 1
AS
BEGIN
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
SET NOCOUNT ON;
select
node.id
--,node.text,node.createDate,dataDate
from umbraconode node
inner join cmsDocument doc on node.id = doc.nodeId
inner join cmsPropertyData prop on prop.contentNodeId = node.id and prop.propertytypeid = 121 -- prop 121 is publishedDate
inner join cmsContentVersion v on v.ContentId = node.id and VersionDate = (select MAX(VersionDate) from cmsContentVersion where ContentId = node.id)
where node.parentID = 1124 AND doc.published = 1 -- parent 1121 is the articles index node
and
prop.versionId = (select top 1 cmsContentVersion.VersionId from cmsContentVersion
where cmsContentVersion.ContentId = node.id order by cmsContentVersion.VersionDate desc)
order by prop.dataDate desc
OFFSET @PageSize * (@PageNumber - 1) ROWS
FETCH NEXT @PageSize ROWS ONLY OPTION (RECOMPILE);
END
GO
sorting in Umbraco sucks
I think this is a common scenario:
I have a site with about 40K documents. The website has a homepage which shows the most recently added content.
To show the latest content, I sort by a "publication date" property. Obviously, you want to do this in Examine, to avoid instantiating all 40,000 nodes. However, it appears to be impossible to sort by a custom property with Examine.
Here is how the Examine unit tests do it. This does not work for a custom property.
So this does not sort anything:
Sorting the IPublishedContent list works, but this means that my homepage takes several minutes to load and requires 8GB of memory.
It seems I have no option by to bypass Umbraco entirely and do the sorting in a stored procedure.
Has anyone else dealt with this?
Here is the stored procedure version, which is unfortunately still quite slow:
Hi David,
For sorting to work with examine you need to enable it in the examine configuration for it
See https://our.umbraco.org/documentation/Reference/Config/ExamineSettings/ for more information
Example :
Dave
Thanks Dave. That worked. Is there a benefit to using a new index set?
After some experimentation, this appears to work moderately fast:
...
Presumably you are using a cached partial so it doesn't need to perform this operation every page load?
is working on a reply...