Skip to content
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 tree-generation prepopulation #8391

Closed
4 tasks done
sminnee opened this issue Sep 19, 2018 · 8 comments
Closed
4 tasks done

Refactor tree-generation prepopulation #8391

sminnee opened this issue Sep 19, 2018 · 8 comments

Comments

@sminnee
Copy link
Member

sminnee commented Sep 19, 2018

Problem

Right now CMSMain::SiteTreeAsUL() calls some Versioned prepopulation in order to generate the site tree without an egregious number of queries. This works okay, but has a couple of challenges:

This relates to silverstripe/silverstripe-cms#2250.

Recommended fix

This logic should be wrapped into a prepopulateTreeDataCache method:

singleton('SiteTree')->prepopulateTreeDataCache(DataList $recordList = null, array $options)

  • $recordList: An optional DataList of the records to include in the prepopulation. By default, all records will be included.
  • $options: A map of metadata to assist. None of this should be assumed to be supplied, but it can be used to optimise any prepopulation, where appropriate.
    • 'childrenMethod': The name of the method on the record used to get children
    • 'numChildrenMethod': The name of the method on the record used to get number of children

Hierarchy can provide this method, since it relates to trees, and other extensions can hook into the behaviour by defining onPrepopulateTreeDataCache. The existing behaviour can be shifted to Versioned::onPrepopulateTreeDataCache, and the fluent ticket above could be implemented by providing this.

Pull requests

@sminnee
Copy link
Member Author

sminnee commented Sep 19, 2018

Paging @silverstripe/core-team especially @tractorcow.

@chillu
Copy link
Member

chillu commented Sep 20, 2018

The existing behaviour can be shifted to Versioned::onPrepopulateTreeDataCache, and the fluent ticket above could be implemented by providing this.

Wouldn't fluent ideally replace the versioned implementation of this, to avoid running two expensive queries across potentially all records? That seems incompatible with the event hook approach (onPrepopulateTreeDataCache). Since it's implemented as a raw SQL query for performance reasons, there's no way to call augmentSQL through an extension. I guess it depends on how long a SELECT ... GROUP BY takes when you run it over 20k+ records. The GROUP BY criteria (ParentID, Locale) should already be indexed, so might not be worth the hassle in terms of performance gains.

@chillu
Copy link
Member

chillu commented Sep 20, 2018

Update: With the project we're testing against (17k records), SELECT ParentID, COUNT(*) FROM SiteTree GROUP BY 1 takes 5ms on my localhost through Vagrant. Should be roughly the same for a remote database, since it's just one call. The fluent version will take a bit longer, but looks like the impact of running both queries in negligible.

@sminnee
Copy link
Member Author

sminnee commented Sep 20, 2018

Fluent is caching a different set of data: hierarchy is caching numChildren, fluent other is caching isLocalisedOnStage.

The numChildren caching would ideally incorporate any query modification that fluent necessitates, which my second implementation (that takes the stageChildren query of a single record and transforms it into a precaching query for all ParentIDs) does.

@sminnee
Copy link
Member Author

sminnee commented Sep 21, 2018

OK this now blocks merge of Scopey's Fluent PR.

@sminnee
Copy link
Member Author

sminnee commented Sep 21, 2018

@maxime-rainville
Copy link
Contributor

The only PR still open on this one is tractorcow-farm/silverstripe-fluent#468.

@robbieaverill
Copy link
Contributor

@maxime-rainville the fluent PR has been merged, so I'll close this ticket - feel free to reopen if I've misunderstood your comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants