Skip to content

Commit

Permalink
ENHANCEMENT: Cache canView results in order to reduce number of datab…
Browse files Browse the repository at this point in the history
…ase queries made, in particular when iterating through chld pages
  • Loading branch information
gordonbanderson committed Apr 2, 2014
1 parent 5fdc2f1 commit 410cfb0
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion code/model/SiteTree.php
Expand Up @@ -850,6 +850,15 @@ public function canAddChildren($member = null) {
}


public function canView($member = null, $ancestryChecked = false) {
if (!isset($this->CachedCanView)) {
$this->CachedCanView = $this->UncachedCanView($member,$ancestryChecked);
}
return $this->CachedCanView;
}



/**
* This function should return true if the current user can view this
* page. It can be overloaded to customise the security model for an
Expand All @@ -868,7 +877,7 @@ public function canAddChildren($member = null) {
* @param boolean $ancestryChecked
* @return boolean True if the current user can view this page.
*/
public function canView($member = null, $ancestryChecked = false) {
private function UncachedCanView($member = null, $ancestryChecked = false) {
if(!$member || !(is_a($member, 'Member')) || is_numeric($member)) {
$member = Member::currentUserID();
}
Expand Down

0 comments on commit 410cfb0

Please sign in to comment.