block-options icon indicating copy to clipboard operation
block-options copied to clipboard

Slow wp init due to Gutenberghub_Styles_Manager_Blocks->register hook (1+ seconds)

Open oboote opened this issue 1 month ago • 0 comments

Whilst troubleshooting poor page generation performance, we narrowed down the biggest offender to the register hook of Gutenberghub_Styles_Manager_Blocks

We fixed it by patching the plugin to make use of transient caching.

Init went from 1.2s to 0.15s (more in line with expectations)

` register_taxonomy( static::$taxonomy, array( Gutenberghub_Styles_Manager_Admin::$post_type ), $args );

        // Only populate once using a transient
        if ( false === ( $populated = get_transient( 'gms_blocks_populated' ) ) ) {

                $block_types = WP_Block_Type_Registry::get_instance()->get_all_registered();

                foreach ( $block_types as $block_type ) {

                        if ( term_exists( $block_type->name, static::$taxonomy ) ) {
                                continue;
                        }

                        wp_insert_term(
                                $block_type->title,
                                static::$taxonomy,
                                array(
                                        'slug' => str_replace( '/', '___', $block_type->name ),
                                )
                        );
                }

                // Set transient for 12 hours
                set_transient( 'gms_blocks_populated', 1, 12 * HOUR_IN_SECONDS );
        }

`

oboote avatar Nov 06 '25 10:11 oboote