Make WordPress Core

Changeset 54291


Ignore:
Timestamp:
09/23/2022 01:58:19 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Block Editor: Remove repetitive calls to file_get_contents() in block editor settings.

The get_default_block_editor_settings() function used to repeatedly get the default-editor-styles.css file contents without any implementation to avoid this.

This commit utilizes a static variable to remove repetitive calls made during the same request. In tests ran on the front page of a site using Xdebug & Webgrind, the total file_get_contents() invocation count goes down from 181 to 93, and total self cost (the time that the function is responsible for) goes down from 160 ms to 93 ms.

Follow-up to [52042].

Props aristath, mukesh27.
Fixes #56637.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-editor.php

    r54272 r54291  
    193193        // themes without their own editor styles.
    194194        $default_editor_styles_file = ABSPATH . WPINC . '/css/dist/block-editor/default-editor-styles.css';
    195         if ( file_exists( $default_editor_styles_file ) ) {
     195
     196        static $default_editor_styles_file_contents = false;
     197        if ( ! $default_editor_styles_file_contents && file_exists( $default_editor_styles_file ) ) {
     198                $default_editor_styles_file_contents = file_get_contents( $default_editor_styles_file );
     199        }
     200
     201        $default_editor_styles = array();
     202        if ( $default_editor_styles_file_contents ) {
    196203                $default_editor_styles = array(
    197                         array( 'css' => file_get_contents( $default_editor_styles_file ) ),
     204                        array( 'css' => $default_editor_styles_file_contents ),
    198205                );
    199         } else {
    200                 $default_editor_styles = array();
    201206        }
    202207
Note: See TracChangeset for help on using the changeset viewer.