Panel slow when creating a new page after 2.3 upgrade

I upgraded yesterday to 2.3 and since then the panel is slow when creating a new page, or saving a page.

In particular, the loading white bar at the top of the browser (within Kirby), slowly progresses when I save a page, then finally hangs at 98% or so…

If I refresh the browser, the page seem to have been saved correctly.

Any idea of what could it be?

It seems connected to some hooks I am using in my config.php.

In fact, when I remove these hooks, the pages get saved quickly.

The hook in question is the following. It renames files names to match the page title.

// Rename and sanitize file names on panel save
kirby()->hook('panel.page.update', function($page) {
    $count = 0;
    $title = $page->title();
    $images = $page->images();
    foreach ($images as $image) {
        $count++;

        // Remove dots in name
        $search = array(".");
        $replace = array("");
        $title = str_replace($search, $replace, $title);


        // Add 0 before $count so that it is two digits
        $count = str_pad($count, 2, '0', STR_PAD_LEFT);
        $old_filename = $image->filename();
        $filename = $title . "-" . $count;
        if (strpos($old_filename, 'box') !== false) {
            $filename = $filename . "-box";
        } elseif (strpos($old_filename, 'logo') !== false) {
            $filename = $filename . "-logo";
        } elseif (strpos($old_filename, 'advertising') !== false) {
            $filename = $filename . "-advertising";
        }
        $image->rename($filename);
    };
});

I have tried commenting out all the function and leaving kist the empty hook, and it is still slow. If I do remove the hook, the panel returns to be quick … :sweat:

kirby()->hook('panel.page.update', function($page) {
});

Do you happen to use a plugin that uses a hook as well?

This topic may help: Plugin with hook has slow panel progressbar

Yes indeed! I went in my plugins folder and when I deactivate AutoID (https://github.com/helllicht/kirby-autoid) the panel is again snappy.

The plugin uses the following hooks. Do you notice anything wrong I could try fix?

// Set id for new pages
kirby()->hook('panel.page.create', function($page) use ($plugin) {
    return $plugin->onPageCreate($page);
});

// Set id for existing pages (if added later)
kirby()->hook('panel.page.update', function($page) use ($plugin) {
    // trigger update only with version 2.2.2 or higher
    $version = intval(str_replace('.', '', panel()->version()));
    if($version >= 222) {
        return $plugin->onPageUpdate($page);
    } else {
        // do nothing, because of a kirby bug: https://github.com/getkirby/panel/issues/667
    }
});

It seems that since 2.3 we suddenly have this problem with multiple hooks that did not exist before.

If you don’t need the update hook for existing pages in the autoid plugin, you can try to simply remove that hook there. Then your update hook should work again.

Related topics:

@texnixe @lukasbestle

Can we expect a Kirby 2.3.1 release for bug fixes? Soon? :slight_smile:

There will be a 2.3.1 release, but that’s done when it’s done. :slight_smile:

2 Likes

I have updated kirby.php as indicated in the following link and now it works well :slight_smile:

Thanks for the help!

https://github.com/getkirby/kirby/pull/452/commits/33b55fda65c39050d5e4483461f79e9de1efdcad