IBX-10174 Add limit option to getSubtreeSize #412
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.



v3/V4What
This PR adds a new "$limit" option to the
LocationService::getSubtreeSizequery in order to reduce the effects of expensive count queries within the CMS.In #360 the
LocationService::getSubtreeSizewas introduced to address prior issues with the priorLocationService::countbeing two slow. This PR aims to follow on from that by addressing further issues withLocationService::getSubtreeSizeresulting in disproportionately slow queries in it's own right.This has been done by adding a function to limit the overall selected
subTreesize by changing the public API fromTo
Why
In some circumstances (Where a content object may have a large number of child items) the impact of a single call to the
getSubtreeSizefunction can account for over 30 percent of the total page load timeSee the following flame chart for loading the "view" page in the CMS for a content object with a large number of sub-items:

With this patch included this becomes

The time the function takes to resolve falls from
407MS->1MSfor what is functionally the same query.How
This PR introduces a
$limitparameter that targets the use case presented byIsWithinCopySubtreeLimit(The only usecase presented by the current eZ Codebase). The query is aiming to ascertain if there are more than a number of given number of sub items in a content object tree.The current implementation is prone to over scanning the table due to there being no limit properly set on the table in relation to the primary usecase for the function.
The query it currently generates is:
Which performs an entire table scan against existing indexes:
In the new approach the query is terminated early resulting in much faster query times
which gives
Special care has been taken so that no existing code paths should be effected by this change given the new query is only used if a limitation is supplied (where by default it is not)
Checklist:
$ composer fix-cs).@ezsystems/engineering-team).