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'
];
protected $guarded = [];
protected $subpages = [];
protected $subpagesInit = false;
const STATUS_DELETED = 'deleted';
const STATUS_DRAFT = 'draft';
const STATUS_PROTECTED = 'protected';
@@ -76,9 +78,14 @@ class Content extends Model
*/
public function subpages()
{
return $this->getPageQuery()
->where('parent_id', $this->id)
->get();
if (!$this->subpagesInit) {
$this->subpages = $this->getPageQuery()
->where('parent_id', $this->id)
->get();
$this->subpagesInit = true;
}
return $this->subpages;
}
/**