Minor change in the pages architecture
In the Content Management team, we have spent some time analyzing the gaps in the Pages API performance and we have implemented the first steps to bring some improvements into Kentico 8.1.
Among other things, we have identified the performance loss that occurred when creating new pages which caused the number of child pages being updated for the parent page. This led to additional database load to get the number of children and to update the parent record.
After the analysis, we found out that everywhere in our system, the number of child pages was used only to decide if the page had or didn’t have children. Therefore, we decided to replace this information only with a simple yes/no flag, so that there is no need to update the number every time a child page is created.
What’s the change in the database?
The number of child pages was stored in the NodeChildNodesCount column of the CMS_Tree table. This column was replaced with a new NodeHasChildren column containing just the flag.
If you use the NodeChildNodesCount column in your custom queries just to check if there are any child pages, simply use the NodeHasChildren column instead.
If you use the column to get the number of child pages, you need to change your queries to include the number.
Let’s say you have the following query:
SELECT NodeAliasPath, NodeChildNodesCount FROM CMS_Tree
Here is an example of how you can also include the number of child pages:
SELECT NodeAliasPath, ISNULL(C.Count, 0) as NodeChildNodesCount
FROM CMS_Tree AS Data
LEFT JOIN
(
SELECT NodeParentID, count(*) Count
FROM CMS_Tree
GROUP BY NodeParentID
) AS C
ON NodeID = C.NodeParentID
What’s the change in the API?
The TreeNode class representing a page has a property NodeChildNodesCount, which is now obsolete, and uses the Children collection to get the number of child pages for backward compatibility. Now there is a new NodeHasChildren property which reflects the database column.
Similar recommendations as for the database apply to the API. To get the number of child pages, use the Children collection and its Count property. Just bear in mind that an additional query needs to be executed against the database to get the number of pages.