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

FIX: Use Hierarchy::prepopulateTreeDataCache() in CMS. #183

Merged
merged 2 commits into from
Sep 25, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/Versioned.php
Original file line number Diff line number Diff line change
Expand Up @@ -2311,6 +2311,20 @@ public static function get_versionnumber_by_stage($class, $stage, $id, $cache =
return $version ?: null;
}

/**
* Hook into {@link Hierarchy::prepopulateTreeDataCache}.
*
* @param DataList $recordList The list of records to prepopulate caches for. Null for all records.
* @param array $options A map of hints about what should be cached. "numChildrenMethod" and
* "childrenMethod" are allowed keys.
*/
public function onPrepopulateTreeDataCache(DataList $recordList = null, array $options = [])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated Hierachy::prepopulateTreeDataCache to accept an array of IDs as well as DataList. My rational at the time was that if I'm getting a list of IDs as parameters on a request it sounds counter-intuitive that I should fetch them so I can cache something about them.

Ideally onPrepopulateTreeDataCache should mimic this behavior as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For simplicity, we can probably refactor the whole thing to only receive an ID list.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, scratch that. DataList would be the only way that you could supply a lazily-evaluated list, since we can't use "iterable" as a typehint in PHP 5.6/7.0.

{
$idList = $recordList ? $recordList->column('ID') : null;
self::prepopulate_versionnumber_cache($this->owner->baseClass(), Versioned::DRAFT, $idList);
self::prepopulate_versionnumber_cache($this->owner->baseClass(), Versioned::LIVE, $idList);
}

/**
* Pre-populate the cache for Versioned::get_versionnumber_by_stage() for
* a list of record IDs, for more efficient database querying. If $idList
Expand Down