ClassicPress / ClassicPress-v2

NOT READY FOR PRODUCTION.
GNU General Public License v2.0
13 stars 4 forks source link

WP-r55657: Users: Cache database queries within WP_User_Query class #267

Closed mattyrob closed 12 months ago

mattyrob commented 1 year ago

Description

Users: Cache database queries within WP_User_Query class.

Cache the results of database queries within WP_User_Query class. Only cache queries that are requesting 3 or less fields so that caches are not storing full user objects. Cache results are stored in a new global cache group named users-queries. Add a new parameter to WP_User_Query called cache_results to allow developers to opt out of a receiving cached results. cache_results parameter defaults to true. Also add a new helper function called wp_cache_set_users_last_changed, similar to wp_cache_set_posts_last_changed that incroments last changed value in cache group users. Ensure that wp_cache_set_users_last_changed is called whenever user / user meta is modified for proper cache invalidation.

Props johnjamesjacoby, spacedmonkey, westi, dd32, strategio, srikanthmeenakshi, OllieJones, khoipro, rjasdfiii, flixos90, mukesh27, peterwilsoncc.

https://core.trac.wordpress.org/changeset/55657

Motivation and context

Backport of upstream efficiency enhancement

How has this been tested?

This is a backport, local tests have been passing.

Screenshots

N/A

Types of changes

xxsimoxx commented 1 year ago

Running unit tests on my MAMP stack:

There were 2 errors:

1) Tests_Admin_WpAutomaticUpdater::test_is_allowed_dir_should_return_true_if_open_basedir_is_set_and_path_is_allowed
PHPUnit\Framework\Exception: PHP Warning:  file_put_contents(): open_basedir restriction in effect. File(/private/var/folders/qw/yd47hwjd0dz1c0b6582l_8840000gn/T/phpunit_Mcg0xl) is not within the allowed path(s): (/Users/simo/Sites/) in Standard input code on line 92
PHP Warning:  file_put_contents(/private/var/folders/qw/yd47hwjd0dz1c0b6582l_8840000gn/T/phpunit_Mcg0xl): Failed to open stream: Operation not permitted in Standard input code on line 92

/Users/simo/Sites/ClassicPress-v2/vendor/bin/phpunit:123

2) Tests_Admin_WpAutomaticUpdater::test_is_allowed_dir_should_return_false_if_open_basedir_is_set_and_path_is_not_allowed
PHPUnit\Framework\Exception: PHP Warning:  file_put_contents(): open_basedir restriction in effect. File(/private/var/folders/qw/yd47hwjd0dz1c0b6582l_8840000gn/T/phpunit_z4FPa2) is not within the allowed path(s): (/Users/simo/Sites/) in Standard input code on line 92
PHP Warning:  file_put_contents(/private/var/folders/qw/yd47hwjd0dz1c0b6582l_8840000gn/T/phpunit_z4FPa2): Failed to open stream: Operation not permitted in Standard input code on line 92

/Users/simo/Sites/ClassicPress-v2/vendor/bin/phpunit:123
mattyrob commented 1 year ago

These issues are fixed in #218 already but I made this backport about 3 months ago and that test fix was added about 5 weeks ago. The branch could be sync'd to develop or we can ignore these local issues.

mattyrob commented 12 months ago

Has two approvals, merging in preparation for v2 repository migration.