[wp-trac] [WordPress Trac] #58319: Improve performance of get_block_theme_folders
WordPress Trac
noreply at wordpress.org
Mon May 15 16:32:54 UTC 2023
#58319: Improve performance of get_block_theme_folders
--------------------------+------------------------------
Reporter: spacedmonkey | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Editor | Version: 5.9
Severity: normal | Resolution:
Keywords: | Focuses: performance
--------------------------+------------------------------
Comment (by swissspidy):
`is_dir()` is much faster than `file_exists` for checking directory
existence. On the other hand, `file_exists()` also checks if the directory
can be accessed. See https://bugs.php.net/bug.php?id=78285
So replacing `file_exists( $theme_dir . '/block-templates' )` with
`is_dir( $theme_dir . '/block-templates' )` would be faster. Maybe with
`is_dir( $theme_dir . '/block-templates' ) && is_readable( $theme_dir .
'/block-templates' )` to have the same effect.
-----
Aside: makes me wonder why the following code uses all three checks:
https://github.com/WordPress/wordpress-
develop/blob/c40e0c6f816ed27ba8b75462632498a36f624181/src/wp-includes
/block-patterns.php#L374-L377
That seems like overkill.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/58319#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list