-
Notifications
You must be signed in to change notification settings - Fork 824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor prepopulation #8395
Refactor prepopulation #8395
Conversation
This helper is necessary when you want to replace a parameter with a non-literal such as a column name. This arises when you are transforming queries such as we do in the prepopulation query for Hierarchy::numChildren()
API: Hierarchy::stageChildren() customisations must be applied to the base class and not include record-specific behaviour. Adds the ability to prepopulate the cache for Hierarchy::numChildren() in a batch. Note that this optimisation means that stageChildren() is not called on each record in order to calculate numChildren(). This means that the structure of the stageChildren() query must be the same for all records and the behaviour cannot be customised only for a subclass of the base data class. For example, apply your customisations to SiteTree and not a subclass. This is an useful part of optimising the query count on tree generation. See #8379
This will avoid trying to count the children of childless object.
This provides a more extensible way of preopulating caches for optimised tree generation. Fixes #8391
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like we should comment that this new replace_parameter
function should be used with extreme caution. preg_matching
out identifiers with literals is just a huge opportunity for insecure coding...
*/ | ||
public static function replace_parameter($sql, $paramIdx, $replacement, $skipEscaping = false) | ||
{ | ||
$segments = preg_split('/\?/', $sql); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
explode
would be faster here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed on parent PR by 07f9cdc
I've incorporated this into #8380 |
* FIX: Use Hierarchy::prepopulate_numchildren_cache in tree-generation Only relevant if silverstripe/silverstripe-framework#8380 is avialable, however coded defensively so it can be merged before that PR if needs be. See silverstripe/silverstripe-framework#8379 * FIX: Use Hierarchy::prepopulateTreeDataCache() in CMS. Requires silverstripe/silverstripe-framework#8395 * Cache tree_class instead of assuming it will always be SiteTree.
* FIX: Use Hierarchy::prepopulateTreeDataCache() in CMS. Requires silverstripe/silverstripe-framework#8395
NEW: Add Hierarchy::prepopulateTreeDataCache()
This provides a more extensible way of preopulating caches for optimised
tree generation.
Fixes #8391