Enforce transient deletion and creation in options table when using external object cache.#1653
Enforce transient deletion and creation in options table when using external object cache.#1653
Conversation
…_languages_list transient.
…ll_languages_list transient with PHPUnit tests.
…need to call it then.
… the same instance of PLL_Model to avoid breaking global scope for other tests, do not clean cache to hard between actions, and call languages->set_ready() to allow Polylang to cache languages.
Co-authored-by: Grégory Viguier <[email protected]>
Co-authored-by: Grégory Viguier <[email protected]>
include/Model/Languages.php
Outdated
| public function set_transient_to_options_table( $value ): void { | ||
| if ( wp_using_ext_object_cache() || wp_installing() ) { | ||
| add_option( '_transient_' . self::TRANSIENT_NAME, $value, '', true ); | ||
| } | ||
| } |
There was a problem hiding this comment.
Is it useful? I we previously deleted the transient and at some point the external is not used, the option will be automatically re-created. Am I wrong?
There was a problem hiding this comment.
As discussed during our meeting, this is safer to avoid race conditions between cache and DB.
There was a problem hiding this comment.
We eventually chose to relay only on transient deletion to keep the DB up to date.
So I removed set_transient_to_options_table() in 9d28161.
I also ensure the test fails correctly with this change (if the fix is removed), see ad16085.
Then I took the opportunity to create a dedicated testcase in 9e46188, indeed I'm currently working on the same issue in Polylang Pro and I could use a testcase for it.
include/model.php
Outdated
| add_action( 'delete_transient_pll_languages_list', array( $this->languages, 'delete_transient_from_options_table' ) ); | ||
| add_action( 'set_transient_pll_languages_list', array( $this->languages, 'set_transient_to_options_table' ) ); |
There was a problem hiding this comment.
Since you are using the constant in Languages, it would be better to use it here the action name too.
install/upgrade.php
Outdated
| } | ||
|
|
||
| delete_transient( 'pll_languages_list' ); | ||
| delete_option( '_transient_pll_languages_list' ); // Force deletion of the transient from the options table in case external object cache is used. |
There was a problem hiding this comment.
Why is it necessary? I suppose that the action added above will do its job. Am I wrong?
There was a problem hiding this comment.
For the added hooks to be effective, we must delay the deletion. Done in b01def5.
| @@ -0,0 +1,523 @@ | |||
| <?php | |||
| /** | |||
| * Object Cache Annihilator. | |||
There was a problem hiding this comment.
I guess the source of this file is coming from https://github.com/polylang/object-cache-annihilator.
I suggest to maintain only the plugin and "require-dev" it with composer to re-use it.
uninstall.php
Outdated
| delete_transient( 'pll_languages_list' ); | ||
| delete_option( '_transient_pll_languages_list' ); // Force deletion of the transient from the options table in case external object cache is used. |
There was a problem hiding this comment.
| delete_transient( 'pll_languages_list' ); | |
| delete_option( '_transient_pll_languages_list' ); // Force deletion of the transient from the options table in case external object cache is used. | |
| delete_option( '_transient_pll_languages_list' ); // Force deletion of the transient from the options table in case external object cache is used. |
We don't need to delete the external cache in case of clean uninstall. Do we?
…it in Test_Object_Cache, also ensure to not do anything until the cahce is dropped in in Test_Object_Cache::set_up().
composer.json
Outdated
| "repositories": [ | ||
| { | ||
| "name": "wpsyntex/object-cache-annihilator", | ||
| "type": "vcs", | ||
| "url": "[email protected]:polylang/object-cache-annihilator.git" | ||
| } | ||
| ], |
There was a problem hiding this comment.
I've added the package to Packagist: https://packagist.org/packages/wpsyntex/object-cache-annihilator
SO you shouldn't need this.
Co-authored-by: Chouby <[email protected]>
…ister_shutdown_function to remove Object Cache Annihilator properly in case of fatal error.
…o activate the cache, - ensure database contains the transient - assert the transient from database does not exist in the end.
…ect_cache global with it.
…oot_dir() new method.
…se COmposer API to get the path to the drop-in.
|
I have successfully tested the fix in an environment using Redis (via the Redis Object Cache plugin) to ensure that transients are correctly purged from the external cache. Test :
|
What?
Partially fixes #2125.
How?
pll_languages_listtransient is deleted from options table even if external object cache is used.delete_transient_pll_languages_listhook with new method inLanguagesmodel.wpsyntex/object-cache-annihilatoras dev dependency.Note
Similar work must be done in Polylang Pro for
pll_translated_slugstransient.