Make WordPress Core


Ignore:
Timestamp:
08/29/2022 04:52:12 PM (18 months ago)
Author:
flixos90
Message:

Site Health: Introduce persistent object cache check.

This changeset adds a new persistent_object_cache check which determines whether the site uses a persistent object cache, and if not, recommends it if it is beneficial for the site. A support resource to learn more about object caching has been created and is linked in the check.

A few filters are included for customization of the check, aimed primarily at hosting providers to provide more specific information in regards to their environment:

  • site_status_persistent_object_cache_url filters the URL to learn more about object caching, so that e.g. a hosting-specific object caching support resource could be linked.
  • site_status_persistent_object_cache_notes filters the notes added to the check description, so that more fine tuned information on object caching based on the environment can be provided.
  • site_status_should_suggest_persistent_object_cache is a short-circuit filter which allows using entirely custom logic to determine whether a persistent object cache would make sense for the site.
  • site_status_persistent_object_cache_thresholds filters the thresholds in the default logic to determine whether a persistent object cache would make sense for the site, which is based on the amount of data in the database.

Note that due to the nature of this check it is only run in production environments.

Props furi3r, tillkruss, spacedmonkey, audrasjb, Clorith.
Fixes #56040.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/site-health.php

    r52010 r53955  
    108108        );
    109109    }
     110
     111    /**
     112     * @group ms-excluded
     113     * @ticket 56040
     114     */
     115    public function test_object_cache_default_thresholds() {
     116        $wp_site_health = new WP_Site_Health();
     117
     118        $this->assertFalse(
     119            $wp_site_health->should_suggest_persistent_object_cache()
     120        );
     121    }
     122
     123
     124    /**
     125     * @group ms-required
     126     * @ticket 56040
     127     */
     128    public function test_object_cache_default_thresholds_on_multisite() {
     129        $wp_site_health = new WP_Site_Health();
     130        $this->assertTrue(
     131            $wp_site_health->should_suggest_persistent_object_cache()
     132        );
     133    }
     134
     135    /**
     136     * @ticket 56040
     137     */
     138    public function test_object_cache_thresholds_check_can_be_bypassed() {
     139        $wp_site_health = new WP_Site_Health();
     140        add_filter( 'site_status_should_suggest_persistent_object_cache', '__return_true' );
     141
     142        $this->assertTrue(
     143            $wp_site_health->should_suggest_persistent_object_cache()
     144        );
     145    }
     146
     147    /**
     148     * @dataProvider thresholds
     149     * @ticket 56040
     150     */
     151    public function test_object_cache_thresholds( $threshold, $count ) {
     152        $wp_site_health = new WP_Site_Health();
     153        add_filter(
     154            'site_status_persistent_object_cache_thresholds',
     155            function ( $thresholds ) use ( $threshold, $count ) {
     156                return array_merge( $thresholds, array( $threshold => $count ) );
     157            }
     158        );
     159
     160        $this->assertTrue(
     161            $wp_site_health->should_suggest_persistent_object_cache()
     162        );
     163    }
     164
     165    /**
     166     * Data provider.
     167     *
     168     * @ticket 56040
     169     */
     170    public function thresholds() {
     171        return array(
     172            array( 'comments_count', 0 ),
     173            array( 'posts_count', 0 ),
     174            array( 'terms_count', 1 ),
     175            array( 'options_count', 100 ),
     176            array( 'users_count', 0 ),
     177            array( 'alloptions_count', 100 ),
     178            array( 'alloptions_bytes', 1000 ),
     179        );
     180    }
    110181}
Note: See TracChangeset for help on using the changeset viewer.