Make WordPress Core


Ignore:
Timestamp:
10/03/2023 03:16:55 PM (9 months ago)
Author:
spacedmonkey
Message:

Editor: Improve performance of _register_theme_block_patterns function.

The _register_theme_block_patterns function imposed a significant resource overhead. This issue primarily stems from themes, such as TT4, that register a substantial number of block patterns. These patterns necessitate numerous file operations, including file lookups, file reading into memory, and related processes. To provide an overview, the _register_theme_block_patterns function performed the following file operations:

  • is_dir
  • is_readable
  • file_exists
  • glob
  • file_get_contents (utilized via get_file_data)

To address these issues, caching using a transient has been added to a new function call _wp_get_block_patterns. If theme development mode is disabled and theme exists, the block patterns are saved in a transient cache. This cache is used all requests after that, saving file lookups and reading files into memory. Cache invalidation is done, when themes are switched, deleted or updated. Meaning that block patterns are not stored in the cache incorrectly.

Props flixos90, joemcgill, peterwilsoncc, costdev, swissspidy, aristath, westonruter, spacedmonkey.
Fixes #59490

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/theme.php

    r56639 r56765  
    8282    do_action( 'delete_theme', $stylesheet );
    8383
     84    $theme = wp_get_theme( $stylesheet );
     85
    8486    $themes_dir = trailingslashit( $themes_dir );
    8587    $theme_dir  = trailingslashit( $themes_dir . $stylesheet );
     
    125127        WP_Theme::network_disable_theme( $stylesheet );
    126128    }
     129
     130    // Clear theme caches.
     131    $theme->cache_delete();
    127132
    128133    // Force refresh of theme update information.
Note: See TracChangeset for help on using the changeset viewer.