FEATURE: cache results for Content::subpages()
This commit is contained in:
+10
-3
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user