reduce laravel queries call and memory usage

1.7k Views Asked by At

i face issue in my admin sidebar in laravel project, that i'm using zizaco/entrust package for permissions and roles. if i logging in as admin i see in debugger bar 134 queries called and 15.27 MB of memory usage.

screen shot

i comment some lines in side bar that check user permission it reduced from 134 to 57 and from 15.27 to 13.54 MB.

Note i cached permission in Redis. here is my code, how i can reduce queries and memory usage.

<ul class="navigation navigation-main navigation-accordion">
<li><a href="{{ url('admin') }}"><i class="icon-home4"></i> <span>Dashboard</span></a></li>

@foreach($admin_side_menu as $pers)
    @ability(['owner','admin'], $pers->name)
        <li class="{{ (strpos( $currnt_page, strtolower($pers->as)) !== false) ? "active" : "" }}">
            <a {!! count($pers->children) > 0 ? 'class="has-ul"' : '' !!} href="{{ url(config('app.admin_prefix') . '/' . $pers->route) }}">{!! $pers->icon != null ? '<i class="'.$pers->icon.'"></i>' : '<i class="icon-home4"></i>' !!} <span>{{ $pers->display_name }}</span></a>
            @if (count($pers->children) > 0)
                <ul>
                    @foreach($pers->children->where('appear', '1') as $subpers)
                        @ability(['owner','admin'], $subpers->name)
                            <li class="{{ ($currnt_page == $subpers->as) ? "active" : "" }}"><a href="{{ url(config('app.admin_prefix') . '/' . $subpers->route) }}">{{ $subpers->display_name }}</a></li>
                        @endability
                    @endforeach
                </ul>
            @endif
        </li>
    @endability
@endforeach

when i comment:

@ability(['owner','admin'], $pers->name)
@ability(['owner','admin'], $subpers->name)
@endability
@endability

the queries calls and memory usage are reduced but i want more.

1

There are 1 best solutions below

0
On

Please used the following link. "https://laravel.com/docs/5.5/mix".

It reduce all queries called when run the project.It's laravel build in module that reduce load project and fastly open project.