Skip to content

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

@oboote

Description

@oboote

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 );
        }

`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions