cached main menu
This commit is contained in:
parent
e26647dd41
commit
3f70df54ee
@ -1,5 +1,16 @@
|
|||||||
<div class="clearfix" id="main-menu" data-controller="<?= $this->request()->controller() ?>">
|
<div class="clearfix" id="main-menu" data-controller="<?= $this->request()->controller() ?>">
|
||||||
<?php //local_cache ['menu', current_user()->id, current_user()->level] do ?>
|
<?php
|
||||||
|
/**
|
||||||
|
* MI: how about caching the menu for each user level, instead of each user,
|
||||||
|
* having placeholders for user id and name that will be replaced with current user's
|
||||||
|
* data right before echoing the menu.
|
||||||
|
*/
|
||||||
|
$key = 'menu.'.current_user()->level;
|
||||||
|
$menu = Rails::cache()->read($key);
|
||||||
|
|
||||||
|
if (!$menu) :
|
||||||
|
ob_start();
|
||||||
|
?>
|
||||||
<ul>
|
<ul>
|
||||||
<li class="user"><?= $this->linkTo($this->t('.account._'), ['user#home'], ['onclick' => 'if(!User.run_login_onclick(event)) return false;', 'class' => 'login-button']) ?>
|
<li class="user"><?= $this->linkTo($this->t('.account._'), ['user#home'], ['onclick' => 'if(!User.run_login_onclick(event)) return false;', 'class' => 'login-button']) ?>
|
||||||
<?= $this->linkTo('■', '#', ['class' => 'submenu-button']) ?>
|
<?= $this->linkTo('■', '#', ['class' => 'submenu-button']) ?>
|
||||||
@ -8,12 +19,12 @@
|
|||||||
<li><?= $this->linkTo($this->t('.account.login'), ['controller' => 'user', 'action' => 'login'], ['id' => 'login-link', 'class' => 'login-button']) ?></li>
|
<li><?= $this->linkTo($this->t('.account.login'), ['controller' => 'user', 'action' => 'login'], ['id' => 'login-link', 'class' => 'login-button']) ?></li>
|
||||||
<li><?= $this->linkTo($this->t('.account.reset'), ['controller' => 'user', 'action' => 'reset_password']) ?></li>
|
<li><?= $this->linkTo($this->t('.account.reset'), ['controller' => 'user', 'action' => 'reset_password']) ?></li>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<li><?= $this->linkTo($this->t('.account.profile'), ['controller' => 'user', 'action' => 'show', 'id' => current_user()->id]) ?></li>
|
<li><?= $this->linkTo($this->t('.account.profile'), ['controller' => 'user', 'action' => 'show', 'id' => "-user.id-"]) // MI: -user.id- ?></li>
|
||||||
<li><?= $this->linkTo($this->t('.account.mail'), ['controller' => 'dmail', 'action' => 'inbox']) ?></li>
|
<li><?= $this->linkTo($this->t('.account.mail'), ['controller' => 'dmail', 'action' => 'inbox']) ?></li>
|
||||||
<li><?= $this->linkTo($this->t('.account.favorites'), ['controller' => 'post', 'action' => 'index', 'tags' => "order:vote vote:3:".current_user()->name]) ?></li>
|
<li><?= $this->linkTo($this->t('.account.favorites'), ['controller' => 'post', 'action' => 'index', 'tags' => "order:vote vote:3:-user.name-"]) // MI: -user.name- ?></li>
|
||||||
<li><?= $this->linkTo($this->t('.account.settings'), ['controller' => 'user', 'action' => 'edit']) ?></li>
|
<li><?= $this->linkTo($this->t('.account.settings'), ['controller' => 'user', 'action' => 'edit']) ?></li>
|
||||||
<li><?= $this->linkTo($this->t('.account.change_password'), ['controller' => 'user', 'action' => 'change_password']) ?></li>
|
<li><?= $this->linkTo($this->t('.account.change_password'), ['controller' => 'user', 'action' => 'change_password']) ?></li>
|
||||||
<li><?= $this->linkTo($this->t('.account.logout'), ['controller' => 'user', 'action' => 'logout'], ['from' => $this->request()->path()]) ?></li>
|
<li><?= $this->linkTo($this->t('.account.logout'), ['controller' => 'user', 'action' => 'logout']/* (MI: Since menu is cached, this doesn't make sense) , ['from' => $this->request()->path()]*/) ?></li>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
@ -208,5 +219,16 @@
|
|||||||
</ul>
|
</ul>
|
||||||
<span id='cn' style="display: none;">
|
<span id='cn' style="display: none;">
|
||||||
</span>
|
</span>
|
||||||
<?php //end ?>
|
<?php
|
||||||
|
$menu = ob_get_clean();
|
||||||
|
Rails::cache()->write($key, $menu);
|
||||||
|
endif;
|
||||||
|
|
||||||
|
if (!current_user()->is_anonymous()) {
|
||||||
|
$menu = substr_replace($menu, current_user()->id, strpos($menu, '-user.id-'), 9);
|
||||||
|
echo substr_replace($menu, current_user()->name, strpos($menu, '-user.name-'), 11);
|
||||||
|
} else {
|
||||||
|
echo $menu;
|
||||||
|
}
|
||||||
|
?>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user