Skip to content

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

@oboote

Description

@oboote

EDIT: Posted feedback in wrong repo - closing.

Description

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

Step-by-step reproduction instructions

Normal use of plugin. Potentially related to many dynamic blocks due to WPML + ACF.

Screenshots, screen recording, code snippet or Help Scout ticket

No response

Environment info

No response

Is the issue you are reporting a regression

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis label could be used to identify issues that are caused by a defect in the product.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions