From: Vincent Vanwaelscappel Date: Tue, 16 Jul 2019 13:46:52 +0000 (+0200) Subject: #2889 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=183fa2304245a5d99eb8827206dd906c64d4e1e0;p=cubist_cms-back.git #2889 --- diff --git a/src/app/Magic/Controllers/CubistMagicController.php b/src/app/Magic/Controllers/CubistMagicController.php index ae7ea9b..4ada7d9 100644 --- a/src/app/Magic/Controllers/CubistMagicController.php +++ b/src/app/Magic/Controllers/CubistMagicController.php @@ -12,6 +12,7 @@ use Cubist\Backpack\app\Magic\Requests\CubistMagicStoreRequest; use Cubist\Backpack\app\Magic\Requests\CubistMagicUpdateRequest; use Gaspertrix\Backpack\DropzoneField\Traits\HandleAjaxMedia; use Illuminate\Support\Arr; +use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Redirect; class CubistMagicController extends CubistCrudController @@ -62,7 +63,7 @@ class CubistMagicController extends CubistCrudController $this->crud->allowAccess('revisions'); $this->crud->setEditView('cubist_back::edit'); - if($this->_nested){ + if ($this->_nested) { $this->crud->allowAccess('reorder'); $this->crud->enableReorder('name', 4); } @@ -188,6 +189,8 @@ class CubistMagicController extends CubistCrudController */ public function store(CubistMagicStoreRequest $request) { + $this->_forgetCache(); + $request = $this->_prepareCRUDData($request); $this->getModelInstance()->onBeforeStore($this, $request); @@ -204,6 +207,8 @@ class CubistMagicController extends CubistCrudController */ public function update(CubistMagicUpdateRequest $request) { + $this->_forgetCache(); + $request = $this->_prepareCRUDData($request); $this->getModelInstance()->onBeforeUpdate($this, $request); @@ -214,6 +219,10 @@ class CubistMagicController extends CubistCrudController return $redirect_location; } + protected function _forgetCache() + { + Cache::forget('navigation'); + } public function index() { diff --git a/src/app/Magic/Menu/Menu.php b/src/app/Magic/Menu/Menu.php index 4112ba8..8fca833 100644 --- a/src/app/Magic/Menu/Menu.php +++ b/src/app/Magic/Menu/Menu.php @@ -3,6 +3,7 @@ namespace Cubist\Backpack\app\Magic\Menu; use Lavary\Menu\Menu as BaseMenu; +use Illuminate\Support\Facades\Cache; class Menu extends BaseMenu { @@ -25,10 +26,13 @@ class Menu extends BaseMenu public static function getNavigation() { if (self::$_nav === null) { - Debugbar::startMeasure('nav', 'Init Navigation object'); - self::$_nav = new Item(); - self::$_nav->initFromDatabase(); - Debugbar::stopMeasure('nav'); + \Barryvdh\Debugbar\Facade::startMeasure('nav', 'Init Navigation object'); + self::$_nav = Cache::remember('navigation', 43200, function () { + $nav = new Item(); + $nav->initFromDatabase(); + return $nav; + }); + \Barryvdh\Debugbar\Facade::stopMeasure('nav'); } return self::$_nav; diff --git a/src/app/Magic/Menu/PageItem.php b/src/app/Magic/Menu/PageItem.php index 50fa504..b6afc7d 100644 --- a/src/app/Magic/Menu/PageItem.php +++ b/src/app/Magic/Menu/PageItem.php @@ -30,7 +30,8 @@ class PageItem extends Item public function setChildrenFromTemplate() { - $this->getPage()->getUsedTemplate()->setMenuChildren($this); + $template=$this->getPage()->getUsedTemplate(); + $template->setMenuChildren($this); } public function getHref()