FEATURE: cache results for Content::subpages()

This commit is contained in:
Michal Kváček
2016-04-02 19:11:46 +02:00
parent 31c1648597
commit ce030a40d4
+10 -3
View File
@@ -30,6 +30,8 @@ class Content extends Model
'status' 'status'
]; ];
protected $guarded = []; protected $guarded = [];
protected $subpages = [];
protected $subpagesInit = false;
const STATUS_DELETED = 'deleted'; const STATUS_DELETED = 'deleted';
const STATUS_DRAFT = 'draft'; const STATUS_DRAFT = 'draft';
const STATUS_PROTECTED = 'protected'; const STATUS_PROTECTED = 'protected';
@@ -76,9 +78,14 @@ class Content extends Model
*/ */
public function subpages() public function subpages()
{ {
return $this->getPageQuery() if (!$this->subpagesInit) {
->where('parent_id', $this->id) $this->subpages = $this->getPageQuery()
->get(); ->where('parent_id', $this->id)
->get();
$this->subpagesInit = true;
}
return $this->subpages;
} }
/** /**