We've retired the forum in favor of GitHub Discussions.

New conversations can be started on GitHub. Existing conversations will remain for a while longer.

Head over to GitHub →

Extending CP makes requests 10x slower

Andreas August 17, 2021 by Andreas

I extended the CP to show reported posts in a community so admins can deal with those posts directly in the CP. As of now, I'm not even returning any data. But after implementing the basics, I noticed that all requests were significantly slower, across the whole page, not just the CP. So even regular Laravel routes took much longer to load.

Here is what I did:

In my AppServiceProvider I added this:

Statamic::pushCpRoutes(function () {
    Route::namespace('\App\Http\Controllers')->group(function () {
        require base_path('routes/cp.php');
    });
});

In my config/app.php I added this line:

App\Services\StatamicCPExtend::class

My StatamicCPExtend class looks like this:

use Statamic\Facades\CP\Nav;
use Statamic\Providers\AddonServiceProvider;

class StatamicCPExtend extends AddonServiceProvider
{
    protected $routes = [
        'cp' => __DIR__ . '/../routes/cp.php',
    ];

    public function boot()
    {
        parent::boot();

        $this->createNavigation();
    }

    protected function createNavigation()
    {
        Nav::extend(function ($nav) {
            $nav->tools('Community')
                ->route('emcommunity.users')
                ->icon('users')
                ->active('emcommunity')
                ->children([
                    $nav->item('Gemeldete Beiträge')->route('emcommunity.reports')
                ]);
        });
    }
}

The reports function in my controller looks like this:

public function reports()
{
    return view('cp.community-reports', [
        'title' => 'Community | Gemeldete Beiträge',
        'reports' => []
    ]);
}

After removing the above code, the pages load fast again.

alt text

I'm not able to locate the issue. I wouldn't care if the CP takes a bit longer loading (and not the actual website), so maybe this whole logic could be only applied to the CP. Would that be possible and if so, how?

Answered by Andreas!
>>>>>>> Answered <<<<<<<
2 Replies
2 Followers