[wp-trac] [WordPress Trac] #6: the_excerpt() on non-excerpt posts doesn't stripslashes

WordPress Trac noreply at wordpress.org
Fri Feb 17 12:33:21 UTC 2023


#6: the_excerpt() on non-excerpt posts doesn't stripslashes
--------------------------------------+---------------------
 Reporter:  anonymousbugger           |       Owner:  ryan
     Type:  defect (bug)              |      Status:  closed
 Priority:  normal                    |   Milestone:
Component:  Template                  |     Version:
 Severity:  minor                     |  Resolution:  fixed
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+---------------------

Comment (by prbot):

 ''This ticket was mentioned in [https://github.com/WordPress/wordpress-
 develop/pull/4097 PR #4097] on [https://github.com/WordPress/wordpress-
 develop/ WordPress/wordpress-develop] by
 [https://profiles.wordpress.org/oandregal/ @oandregal].''
 ## What

 This PR improves the performance of block template resolution.

 ## Why

 In a production-like environment, **it provides a two-digit improvement
 for themes with block templates**: +15% for TwentyTwentyThree and +25% for
 TwentyTwentyTwo.

 This change does not affect themes that don't have block templates. The
 variance reported for classic themes can be ignored (lower than 1ms), and
 should be attributed to the variance of the doing the tests: template
 resolution is unaffected for classic themes, given they
 [https://github.com/WordPress/wordpress-
 develop/blob/4049c5d3543e59f92d48fd9cef735420996dce2e/src/wp-includes
 /block-template.php#L51 bail early] if they don't support block templates.

 [[Image(https://i0.wp.com/user-
 images.githubusercontent.com/583546/219651244-4310263d-a116-4e51-b481-c517360b748a.png)]]

 ## How

 The `get_block_templates` function is responsible to find block templates
 that match a given search. The function is provided a query parameter that
 is used to find the relevant user templates (database) and theme templates
 (file directory). The query parameter includes data such the slugs of the
 templates or the areas of the template parts.

 I've found that the `get_block_templates` retrieves and processes
 [https://github.com/WordPress/wordpress-
 develop/blob/4049c5d3543e59f92d48fd9cef735420996dce2e/src/wp-includes
 /block-template-utils.php#L977 all block templates provided by the theme],
 to later [https://github.com/WordPress/wordpress-
 develop/blob/4049c5d3543e59f92d48fd9cef735420996dce2e/src/wp-includes
 /block-template-utils.php#L997 ignore the ones that don't match the given
 slug].

 This function can be more performant if it only retrieves/processes the
 templates that match a given slug, instead of them all.

 The following profile shows the impact of this modification:

 | Before | After |
 | --- | --- |
 | [[Image(https://i0.wp.com/user-
 images.githubusercontent.com/583546/219652222-2aca88ad-c4b4-4d6f-9b3f-
 707df626711e.png)]] | [[Image(https://i0.wp.com/user-
 images.githubusercontent.com/583546/219652291-3c1f3246-4ac4-49f8-a087-50949f21b48b.png)]]
 |

 - The time it takes as measured by XDebug profiler: 55ms (before) vs 27ms
 (after).
 - The number of times the `_build_block_template_result_from_file` is
 called: 22 (before) vs 5 (after).

 ## How to test

 - Start the bundled environment.
 - Set `.env` to production by applying the following patch:

 {{{diff
 diff --git a/.env b/.env
 index 63a8169f64..9b1d52ac50 100644
 --- a/.env
 +++ b/.env
 @@ -54,10 +54,10 @@ LOCAL_DB_TYPE=mysql
  LOCAL_DB_VERSION=5.7

  # The debug settings to add to `wp-config.php`.
 -LOCAL_WP_DEBUG=true
 -LOCAL_WP_DEBUG_LOG=true
 -LOCAL_WP_DEBUG_DISPLAY=true
 -LOCAL_SCRIPT_DEBUG=true
 +LOCAL_WP_DEBUG=false
 +LOCAL_WP_DEBUG_LOG=false
 +LOCAL_WP_DEBUG_DISPLAY=false
 +LOCAL_SCRIPT_DEBUG=false
  LOCAL_WP_ENVIRONMENT_TYPE=local

  # The URL to use when running e2e tests.
 }}}
 - Run 100 test of the homepage: `seq 100 | xargs -Iz curl -o /dev/null -H
 'Cache-Control: no-cache' -s -w "%{time_starttransfer}\n"
 http://localhost:8889 | xclip -selection clipboard`.
 - Copy the results to a spreadsheet like
 [https://docs.google.com/spreadsheets/d/1K2u5oOh7rd23HBOz3pPAcAi9P8290E0IV2NZhk_E9i4/edit#gid=0
 this one] to measure the changes.

 ## TODO

 - `$fits_slug_query` can be probably removed.
 - Review whether the `area` can be filtered earlier as well.
 - Decide whether this should be prepared for Gutenberg first. I submitted
 it for core because it modifies functions that are no longer there:
   - `_get_block_templates_files`: no longer present.
   - `get_block_templates`: the corresponding
 `gutenberg_get_block_templates` is
 [https://github.com/WordPress/gutenberg/blob/trunk/lib/compat/wordpress-6.1
 /block-template-utils.php#L53 still present], but it'll be removed once
 WordPress 6.2 is published. It won't be present in Gutenberg when this PR
 lands (WordPress 6.3 cycle).

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/6#comment:26>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list